stdcerr
stdcerr

Reputation: 15628

how can i get which month a given year day is in in php?

I have been given year day (1-366) and I need to figure out which month it is in, how can I do this? Well, I actually have a date string like : year, day or year, minute of day, second and I ultimately want to create a POSIX timestamp from it, how can I do this?

Thank you!

Upvotes: 1

Views: 111

Answers (3)

gen_Eric
gen_Eric

Reputation: 227280

If you have PHP >= 5.3, then you can use DateTime::createFromFormat.

$day = 176;
$date = DateTime::createFromFormat('z', $day);
echo $date->getTimestamp();  // 1372275280

Upvotes: 6

Hanky Panky
Hanky Panky

Reputation: 46900

<?php
$year=2013;
$d=360;
echo date("m",strtotime("1/1/$year + $d days")) 
?>

Upvotes: 3

jdog
jdog

Reputation: 2549

Use the date function to get a posix time stamp.

To get the month of a certain date, use intval(date('m'), mktime($h,$m,$s,$month,$day,$year))

Upvotes: 0

Related Questions