Forum Moderators: coopster

Message Too Old, No Replies

Date Manipulation

         

grandpa

4:52 am on Feb 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm obviously missing the finer points of date manipulation. I have this string in my database:

20040228150703

I can read that and see the year, month, day, HH, MM, SS.

My script doesn't return what I see. The db field is called timefield, and is being returned to my qry with everything else. In other words, SELECT *. Then I'm trying to parse out the various pieces.

$ddd = date(DAY,$line['timefield']);
$dwk = date(WEEK,$line['timefield']);
$dmo = date(MONTH,$line['timefield']);
$dyr = date(YEAR,$line['timefield']);

My results from these expressions are humorous at best:
$ddd = MonPM2038
$dwk = 3EEK
$dmo = Jan-0800NPST19
$dyr = 2038EPMR

Help?

ergophobe

5:12 pm on Feb 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The PHP date() function expects a unix timestamp, which this is not.

Suggestion 1.
Don't extract then parse, parse as part of the query, using MySQL's built-in date and time functions [mysql.com] such as DATE_FORMAT.

Suggestion 2.
Use strtotime() to make a date, then use date(). This seems completely backwards to me, but you could make it work if you had some reason to avoid the mysql functions.

Tom