Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text date conversion 1

Status
Not open for further replies.

jmc014

Technical User
Nov 24, 2007
80
ES
Hi there,

I’m trying to create a date (dd/mm/yyyy) from three different text boxes, I’m sure that this has been posted in the past or at least something similar but I can´t anything related.

[txtbox1] gives me 15 while [txtbox2] gives me 11 and [txtbox3]=2010

I´d like [txtMydate] which is a date format to be 15/11/2010.
Any help would be appreciated.
 
A starting point:
txtMydate = DateSerial(txtbox3, txtbox2, txtbox1)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, great it´s working.

Just so that I can understand this a little better, why do the text boxes have to be the other way areound. I mean, why does access give me a totally different date if the text boxes are in order?
 
Look at the help for the DateSerial function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The prototype for the DateSerial function is
Code:
DateSerial (Year, Month, Day)
PHV has placed the text boxes in the correct order to comply with that prototype. If you use some other order (txtbox1, txtbox2, txtbox3) then txtbox1 will be treated as the year; txtbox2 as the month and txtbox3 as the day.

Note also that the arguments to DateSerial do not need to be what we would think of as "valid" values for the Month or Day fields. For example
Code:
DateSerial ( 2010, 22, 37 )    [red]<-- Nov 6, 2011[/red]
is quite valid even though there is obviously no 22nd month or 37th day in any year or month.
 
is quite valid even though there is obviously no 22nd month or 37th day in any year or month.
I find this behaviour quite useful though. In your example the 22nd month of 2010 is October 2011 and the 37th day of October is 6th November.

Both counts wrap round nicely and you don't have to worry about writing code to detect that 22 months will take us past year end so increment the year to 2011 and subtract 12 from 22 to give us month 10.

Geoff Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top