Date Format

  • Thread starter Thread starter fredg
  • Start date Start date
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.
 
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).
 
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]
 
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
 
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.
 
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]
 
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).
 
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

Similar Threads

Code Is Slow 3
Code Is Slow 6
Loop Problem 5
Excel VBA to go to specific sheet & cell in the current workbook not working. 2
Sorting Records 1
Need Help with Date Format 1
DMax Problem 8
getting subform information 2

Back
Top