Welcome Guest, Not a member yet? Register   Sign In
Dates showing up wrong on 31st of the month.
#5

(This post was last modified: 06-01-2017, 04:00 PM by PaulD.)

In your original posted function you are sending something like '-1 months' and setting the variables:

PHP Code:
   $pm = (int) date('n'strtotime($month_num));
 
   $pmy = (int) date('Y'strtotime($month_num)); 

Where 'n' is 1-12 and 'Y' is full year like 2017.

So just change it to (and I am not sure if you mean by -1 months to include last month or just to cover the current month)

PHP Code:
$date = new DateTime('FIRST DAY OF '.$month_num);
$pm  $date->format('n'); 
$pmy $date->format('Y'); 

Nothing will have changed apart from your dates should all work now.

PS have not tested this just wrote it out so might be a bit buggy. In theory it is right.


Edit: Just tested it on phpfiddle and it is working fine, but can't remember my login so can't post a link :-)
Just paste this in and you will see it: http://phpfiddle.org/
PHP Code:
<?php
$month_num 
'-1 months';

$date = new DateTime('FIRST DAY OF '.$month_num);
$pm  $date->format('n'); 
$pmy $date->format('Y'); 

echo 
$pm;
echo 
'<br />';
echo 
$pmy;

?>
Reply


Messages In This Thread
RE: Dates showing up wrong on 31st of the month. - by PaulD - 06-01-2017, 03:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB