News:

Wondering if this will always be free?  See why free is better.

Main Menu

extracting day, month and year from mysql's date

Started by Tim, December 28, 2004, 05:34:53 PM

Previous topic - Next topic

Tim

Mysql stores dates universally as 2004-12-28

I need to extract the year, month and day in 3 different variables, anyone know how?

Christian Land

http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html :
SELECT DAY(your_date_field) AS dtDay, MONTH(your_date_field) AS dtMonth, YEAR(your_date_field) AS dtYear FROM your_table

or

http://www.php.net/manual/en/function.split.php :
list($year,$month,$day) = split("-",$your_date_variable_in_php);

or

http://www.php.net/manual/en/function.explode.php :
$atoms = explode('-',$your_date_variable_in_php);
$year = $atoms[0];
$month = $atoms[1];
$day = $atoms[2];


....and so on...

Tim

thanks :)

classic example of looking at the wrong pages of the reference :)


Advertisement: