Date Format

F

fredg

I have a Textbox with a number in it.

042707

I need to convert this number to a date 04/27/07 and then compare it to the
current date to see if it matches

If Me.TxtNumber = Date() Then
MsgBox "Matches"
ElseIf Me.TxtNumber <> Date() Then
MsgBox "No Match"
End If

Any help is appreciated.
Thanks
DS

So 042707 is text datatype?

If DateSerial(Right([txtNumber],2), Left([TxtNumber],2),
Mid([txtNumber],3,2) = Date() Then
MsgBox "Matches"
Else
MsgBox "Does NOT match"
End If

No need for Elseif if there is only 2 possiblities.
Look up the DateSerial function in VBA help.
 
B

Bob Hairgrove

I have a Textbox with a number in it.

042707

I need to convert this number to a date 04/27/07 and then compare it to the
current date to see if it matches

If Me.TxtNumber = Date() Then
MsgBox "Matches"
ElseIf Me.TxtNumber <> Date() Then
MsgBox "No Match"
End If

Any help is appreciated.
Thanks
DS

Without taking the desired locale into consideration (which might be a different
one from the system locale installed on the client PC), there is no "easy"
comparison that makes sense. There are so many issues regarding ordering and
separators that it is always easiest, in the long run, to design your UI such
that there are separate fields for entry of day, month and year. Then youcan
construct a normalized date value using DateSerial, etc. and do valid
comparisons to the current date as shown by the OS (which might possibly be
incorrect, or in a different time zone, too).
 
J

John W. Vinson

I have a Textbox with a number in it.

042707

I need to convert this number to a date 04/27/07 and then compare it to the
current date to see if it matches

If Me.TxtNumber = Date() Then
MsgBox "Matches"
ElseIf Me.TxtNumber <> Date() Then
MsgBox "No Match"
End If

Any help is appreciated.
Thanks
DS

Access has a pretty good date parser... but it can't recognize just six digits
as a date. Try

If CDate(Format(Me!TxtNumber, "@@/@@/@@")) = Date() Then


John W. Vinson [MVP]
 
D

DS

I have a Textbox with a number in it.

042707

I need to convert this number to a date 04/27/07 and then compare it to the
current date to see if it matches

If Me.TxtNumber = Date() Then
MsgBox "Matches"
ElseIf Me.TxtNumber <> Date() Then
MsgBox "No Match"
End If

Any help is appreciated.
Thanks
DS
 
B

bootybox via AccessMonster.com

Works Great!
Thanks
DS
I have a Textbox with a number in it.
[quoted text clipped - 12 lines]
Thanks
DS

So 042707 is text datatype?

If DateSerial(Right([txtNumber],2), Left([TxtNumber],2),
Mid([txtNumber],3,2) = Date() Then
MsgBox "Matches"
Else
MsgBox "Does NOT match"
End If

No need for Elseif if there is only 2 possiblities.
Look up the DateSerial function in VBA help.
 
B

bootybox via AccessMonster.com

Thanks John, I'll add this to the code for extra safety!
DS
I have a Textbox with a number in it.
[quoted text clipped - 12 lines]
Thanks
DS

Access has a pretty good date parser... but it can't recognize just six digits
as a date. Try

If CDate(Format(Me!TxtNumber, "@@/@@/@@")) = Date() Then

John W. Vinson [MVP]
 
B

bootybox via AccessMonster.com

When you say locale...do you mean a physical location? Europe, USA etc?
Or the PC on a network?
Thanks
DS

Bob said:
I have a Textbox with a number in it.
[quoted text clipped - 12 lines]
Thanks
DS

Without taking the desired locale into consideration (which might be a different
one from the system locale installed on the client PC), there is no "easy"
comparison that makes sense. There are so many issues regarding ordering and
separators that it is always easiest, in the long run, to design your UI such
that there are separate fields for entry of day, month and year. Then you can
construct a normalized date value using DateSerial, etc. and do valid
comparisons to the current date as shown by the OS (which might possibly be
incorrect, or in a different time zone, too).
 
B

Bob Hairgrove

When you say locale...do you mean a physical location? Europe, USA etc?
Or the PC on a network?

The former. Date formats for Canada & the UK are different than US date formats,
for example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top