Page 1 of 1

Extracting month, day, year from a date field in MySQL DB

Posted: Wed Nov 02, 2005 11:04 pm
by korngold
Hi All,

This is probably an easy one, but I just need to extract the numeric value for the month, day, and year of a MySQL Date/Time field. I'm an ASP convert, and in ASP you could simply use month(date), day(date), or year(date). Are there similar functions in PHP? I did google & search the php online manual and came up dry.

Thanks in advance!

Posted: Wed Nov 02, 2005 11:15 pm
by feyd
There are multiple ways. MySQL can perform the such extractions via the EXTRACT() function, or you can use PHP's functions. The function to use from PHP depends on how the information from MySQL is returned. If a DATE/DATETIME type, explode() can be used to break the resultant string apart into array elements; When using a Unix timestamp compatible field (INT), the date() function can be used.

solution

Posted: Wed Nov 02, 2005 11:54 pm
by smartknightinc
hi,

Use date_format() function of mysql

:)
Thanks & Regards
harry

Posted: Thu Nov 03, 2005 1:57 pm
by korngold
Worked like a charm! Thank you!!!