Easy one....

marper
marper used Ask the Experts™
on
Here is an easy one.
I have a variable $dt which has different dates, depending of the connected user in the format 'yyyy-mm-dd'

What's a function that extract only month, and a function that extract only day from a date ?

Example:

$dt == '2002-10-28'
How to get 10 and 28 out of the variable ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
$date=explode('-',$dt);
$date[1] will give 10 and $date[2] will give 28
:-)

//karv
I would use:
$dt = strtotime($dt);  // converts to time
$month = date("m", $dt);  // month
$year = date("Y", $dt);  // year
VGR

Commented:
yes and yes, good solutions, a bit overkill though ;-)

also : substr($dt,5,2) gives you the month 8-)

I leave to your sagacity to find the day ;-)
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Commented:
and a good one :

$dt = '2002-10-28';
list($year, $month, $day) = split("-", $dt);


Author

Commented:
all solutions are good, but as per the site policy, I would need to accept the first one that works.
Thanks a lot to all.

Commented:
no problem :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial