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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

yyyy-mm-dd

Status
Not open for further replies.

Cullen411

Programmer
Aug 17, 2005
89
GB
Just a minor issue,
Before I insert a date into an Access database I am trying to convert to the format YYYY-MM-DD.

Is 1964-7-16 treated exactly the same as 1964-07-16? or should I add 0 to the 7 and then insert?
 
Please don't do this.

Insert the data into a Date/Time field in the database. If you have other applications that need a specific format later on, make them do the conversion. If you are using a Date/Time field right now, then the format your putting in with doesn't matter, it won't be saved. If it is a text field then you will not be able to do anything with that data in the future. Comparisons will do text comprisons (or will require date conversions on the fly in your SQL statement).

The database should store data. Leave it up to your applications to determne how that data will be presented.

barcode_1.gif
 
The database should store data. Leave it up to your applications to determne how that data will be presented.
[cheers] to that

 
The format you insert does matter.

Here's a scenario - you insert a date into an access database which is hosted on an american server. Then you move the Access database to a British server and run the code and insert a date.
Open the database and both dates are in a different format.
Use YYYY-MM-DD and they are not.
 
Here's a scenario - you insert a date into an access database which is hosted on an american server. Then you move the Access database to a British server and run the code and insert a date.
Open the database and both dates are in a different format.

this can never be true since access doesn't really save the dat as such it converts it to an integer or long. That's why access datefield has a beginning (minimum, 0 if you like) and an end (maximum,0 + ...). so access doesn't care how you format them. and it will choose the computers datformat to show it.
Perhaps you are using a string to store your date wich is very wrong.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Chrissie
that's exactly what happened why I ran the code

SQL="INSERT INTO tblDate (dDate) VALUES (#" & Now() & "#)"
on both servers.

I've now got these two records in my database - bear in mind the day difference between servers

08/12/2005 22:25:28
12/09/2005 06:26:59
 
Perhaps a better way to add the data would be to just specify an LCID for this single page, that would force the page to use one set of settings rather than adopting the servers locale. I agree in this one specific occasion that formatting the date might make sense, but there are simpler solutions.

barcode_1.gif
 
Doesn't asp have parameters??

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
And to make a variable be in the format of mm/dd/yyyy (and the final line of code can be modifed for other date formats), perhaps try something like the following which you might even make into a function that you could put on a page that gets included in your main pages:

varFld = CDate(MyVariable)

intMonth = Month(varFld)
intDay = Day(varFld)
intYr = Year(varFld)

If intMonth < 10 Then
strMonth = "0" & CStr(intMonth)
Else
strMonth = CStr(intMonth)
End If

If intDay < 10 Then
strDay = "0" & CStr(intDay)
Else
strDay = CStr(intDay)
End If

strYr = Right(CStr(intYr), 4) ' And change the 4 to 2 for 2 year dates.

varFld = CStr(strMonth & "/" & strDay & "/" & strYr)


Best regards,
J. Paul Schmidt, Freelance Web and Database Developer
Access Database Sample, Web Database Sample, ASP Design Tips
 
Instead of using an if statement to pad a number I prefer to do it this way:

strMonth = Right("00" & CStr(intMonth),2)

Just a different way of doing the same thing, but more flexible in that it can easily be applied to longer numbers too.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top