Page 1 of 1

get day out of datetime

Posted: Wed Jun 23, 2010 1:38 am
by abeloosf
hello,

I'm trying to get the "day" out of a datetime, eg. 2010-06-21 10:00:00... where I want to get a variable containing "21".

As I'm new to PHP I can't get this done, although it seems to be a quite easy function, not?

function get_day($givendatetime) {
$getday = ; // can someone help me with the code i have to put in this line?
return $getday;
}

Any help is very much appreciated!

grtz,

F.

Re: get day out of datetime

Posted: Wed Jun 23, 2010 2:18 am
by Phoenixheart
You may want to use some RegEx. Hint: google for "MySQL date to PHP".
Or, the quick and dirty way:

Code: Select all

$date = explode(' ', $date);
$day = end(explode('-', $date[0]));

Re: get day out of datetime

Posted: Wed Jun 23, 2010 3:05 am
by requinix
Are you getting this date from MySQL? Use the DATE_FORMAT function.