开发者

dates from and to

开发者 https://www.devze.com 2022-12-10 12:52 出处:网络
Hi I have already asked a similar question. but want to make a change like this: I have a starting date and ending date called into a function in php. I need to estrapolate the stating day and month

Hi I have already asked a similar question. but want to make a change like this:

I have a starting date and ending date called into a function in php. I need to estrapolate the stating day and month form the startingDate a开发者_高级运维nd the same for the endingDate, so to make calculation based on day and month.

How do I go about this? Thank you thank you thank you. Francesco


$start_month = date('m',$inStart); $start_day = date('d',$inStart);

$end_month = date('m',$inEnd); $end_day = date('d',$inEnd);


Have a look at the diff method of the DateTime object build into PHP. Presuming you can turn startingDate and endingDate into DateTime objects (perhaps they already are), this will give you what you're looking for.


You could always break down the current date into a timestamp;

list($s_y, $s_m, $s_d) = explode('/', $start_date); $start_date_ts = mktime(12, 12, 12, $s_m, $s_d, $s_y);

list($e_y, $e_m, $e_d) = explode('/', $end_date); $end_date_ts = mktime(12, 12, 12, $e_m, $e_d, $e_y);

Then you'll have $end_date_ts and $start_date_ts, which you can compare and represent with ease.

0

精彩评论

暂无评论...
验证码 换一张
取 消