Page 1 of 1

Datetime format

Posted: Fri Mar 19, 2004 10:52 am
by johnperkins21
I have a mySQL datetime field that I am populating with the SQL now() funtion. The result I get when I pull that out of the database is something like:

2004-03-16 09:58:03

What I want is something like:

Mar 16, 9:58 am


I have looked at date() and strtotime() and mySQL's date_format, but for some reason I am getting very confused. I don't need the code to do it, but an idea of which one of these I should use to do it would help me greatly. That way I can take it and play around with it until I get it working the way I want.

Thanks,
John

Posted: Fri Mar 19, 2004 11:08 am
by Illusionist
i would use the date() function. Then insert it into the database

Posted: Fri Mar 19, 2004 11:42 am
by johnperkins21
If I use the date() function, would my searches still work properly if I sorted by date? I'm using this for a shoutbox, so I like using the now() function for putting it into the database, I just want to change the output. I'm sure that I could use preg_replace somehow, but that looks even more confusing than any of the date functions.

Posted: Fri Mar 19, 2004 11:56 am
by Illusionist
... one question.. why sort by date?? why not have an auto increment field and sort by that?? Thats the way its usually done...

Posted: Fri Mar 19, 2004 11:58 am
by johnperkins21
Umm, because I'm a moron. That's an excellent point. Thanks for your help.

Posted: Fri Mar 19, 2004 12:15 pm
by Illusionist
lol, anytime!! lol

Posted: Fri Mar 19, 2004 12:18 pm
by andre_c
I would insert the date as a database date yyyy-mm-dd and then convert it to whatever format after it's been retrieved, so i can use SQL time/date functions when i do queries. Then to sort it i would just put an 'order by date' at the end of the query

Posted: Fri Mar 19, 2004 12:21 pm
by Illusionist
your just a little late andre_c, i think he already has a solution....??did you read any of the above posts??

Posted: Fri Mar 19, 2004 1:03 pm
by andre_c
I did, but I thought i would give my opinion on a different way of doing it, should i have not done that? sorry, if so.

Posted: Fri Mar 19, 2004 1:39 pm
by johnperkins21
andre_c, different methods are always welcome, but I will invariably take Illusionists suggestion as the SQL time/date functions have me completely baffled. At least PHP's date() function has a little bit of info in the manual I can understand.

Thanks for your input.