Link to home
Create AccountLog in
Avatar of adiemeer
adiemeer

asked on

How to choose the right date format

Hello,

I do have a website where I want to display the last date an user logged in. This information I have stored in a database.  At this moment I use the pattern yyyy-MM-ddTHH:mm:ss.fff
to identify the date. The pattern works well if the stored date is for example 2013-02-15T12:11:41.203. However if the stored date is 2013-02-15T12:11:41.20 this doesn't work well.

How do I have to change the pattern yyyy-MM-ddTHH:mm:ss.fff to read both the dates well? I tried yyyy-MM-ddTHH:mm:ss.ff0, but that didn't work.

Thanks!

Regards Arne
Avatar of AielloJ
AielloJ
Flag of United States of America image

adiemeer,

It sounds like you're storing the date/time in a string format.  Standard practice is to store date/times in the database native format.  When you query the data, formatting functions (which can output almost any format) convert the internal date/time to whatever format you want.  The functions are a little different depending on what database you're using.  Which DB are you using?

Regards,

Aielloj
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
How is it I posted the answer, but got none of the points?