fetching month

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

fetching month

Post by itsmani1 »

2007-03-01T13:15:00 means March 1, 2007 Thursday, 1:15 pm
i am doing

Code: Select all

$date = "2007-03-01T13:15:00";
date("F j, Y<b\\r/>l, g:i a", strtotime(str_replace('T',' ',$date)))
to convert it.
Is there anyway that I can find month from : 2007-03-01T13:15:00

thank you
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Code: Select all

date("F", mktime(0, 15, 13, 03, 01, 2007));
I may have messed up the mktime() parameter order, but you can always look that up.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

like this will return month, date year

Code: Select all

echo date("m.d.y");
is there anything i can pass digit and get the month string and vice versa.

thank you
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

date("F") returns only the month (string/nominal)
date("m") returns only the month (integer)

and you can split() strings to do mktime()
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
$date = "2007-03-01T13:15:00";

// Get the 2 digit numeric of the month
$month = date("m", strtotime(str_replace('T',' ',$date))) ;

// Get the 1 digit numeric of the month (below 10)
$month = date("n", strtotime(str_replace('T',' ',$date))) ;

// Get the short string name of the month
$month = date("M", strtotime(str_replace('T',' ',$date))) ;

// Get the long string name of the month
$month = date("F", strtotime(str_replace('T',' ',$date))) ;
?>
Post Reply