Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Lorraine Stephens   on Mar 01 In MS Office Category.

  
Question Answered By: Audris Schmidt   on Mar 01

I have not answered because the stuff you have posted does not make any sense
to me. I hoped someone else would understand it and help.

The line

varDateOfBirth = Format(DD / MM / YYYY)

Is quite meaningless AFAICS.

The Format function takes an expression and returns a string. You have
defined varDateOfBirth as a date. So you cannot hand it a string. If it was a
variant (which would be the normal reason for starting it with "var") it could
be given a string.

If x was a date, say 31 December 2001 and you used the format function you
could use it like this

Y=format(x,"yy/mm/dd") and y would then hold "01/12/31"

I doi not think this is what you need at all.

I think you need to know what form your input is in. I suspect it is strings
in the form "dd/mm/yyyyy". If so the best bet is to pull each date  apart and
reassemble them to get a julian (A number representing the date)

Make a function Like this:

Function ConvertDate(DateString As Variant) As Date

Dim DateBit, MonthPart, YearPart


DateBit = CInt(Left(DateString, 2))
MonthPart = CInt(mid(DateString, 4, 2))
YearPart = CInt(Right(DateString, 4))

ConvertDate = DateSerial(YearPart, MonthPart, DateBit)

End Function

Then in your main  code you would read the date as a string to a variable, say
strDate

Then you would have a line that said

varDateOfBirth = ConvertDate(strDate)

Now varDateOfBirth contains the correct date and you can use it.

Please let us know how you get on.

I have assumed that your regional settings on your computer are set to read
dates formatted the US way. If not, there will need to be a bit of tweaking
of the code.

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on US/UK Date conflict Or get search suggestion and latest updates.


Tagged: