Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Tim on December 28, 2004, 05:34:53 PM

Title: extracting day, month and year from mysql's date
Post by: Tim on December 28, 2004, 05:34:53 PM
Mysql stores dates universally as 2004-12-28

I need to extract the year, month and day in 3 different variables, anyone know how?
Title: Re: extracting day, month and year from mysql's date
Post by: Christian Land on December 28, 2004, 05:42:35 PM
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...
Title: Re: extracting day, month and year from mysql's date
Post by: Tim on December 28, 2004, 05:51:02 PM
thanks :)

classic example of looking at the wrong pages of the reference :)
Title: Re: extracting day, month and year from mysql's date
Post by: Christian Land on December 28, 2004, 05:54:22 PM
No Problem ;D