I"m going crazy!!!! Date function with timestamp problem
I have the following unix timestamp as a var: 2003-10-02 08:00:00
The var is $start_datetime.
I need to use the date function like so:
date('m/h/Y', $start_datetime) to make the date formatted better.
My problem is that date('m/h/Y', $start_datetime) = 12/06/1969
So I thought, ahh - for some reason it's not a correctly formatted timestamp, so I tried:
date('m/h/Y', strtotime($start_datetime)) = 10/08/2003 - what happened here? - looks like strtotime gave me the 8th?
What is the deal! I've worked for over an hour on this! I want 10/02/2003! See something I'm missing? For codeflow reasons, I'd rather not use mysql to format this string for me.
Any assistance is appreciated!
Are you locked into the timestamp column? Unfortunately, it is not a Unix Timestamp and the date() function takes a unixtimestamp. You can
a) Change the timestamp column to something in line with int(11) and insert a UNIX_TIMESTAMP() into MySQL on insert, or
b) look at mktime() and try to parse out the segments of the timestamp and generate a unixtimestamp in that manner and use that withe the date() function.
Semantically, the second one is more correct. Practically, the first one is simpler and easier.
m = month
h = hour !!!!!!!!!!!
Y = year
I think you need 'd' there ...
Well, of course I need d in there! I was just checking to see if you knew!
just kidding and thanks, Doh!!!!!!!!!!!!!!!!!