get day out of datetime

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abeloosf
Forum Newbie
Posts: 1
Joined: Wed Jun 23, 2010 1:31 am

get day out of datetime

Post 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.
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: get day out of datetime

Post 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]));
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: get day out of datetime

Post by requinix »

Are you getting this date from MySQL? Use the DATE_FORMAT function.
Post Reply