Reputation: 742
I'm using Jason Moon's Calendar Script to allow users to set the date of an event. While this works fine for the year and month, I'm having issues getting it to set the correct day. It consistently sets the date of the event to one day previous to that the user selected; this occurs even if it means going back into the previous month (1 Aug becomes 31 July). I can't figure out why this is or what's doing it!
The client-side code is:
<script>
DateInput('publicationDate', true, "YYYY-MM-DD",
<
?php echo $results['article']->publicationDate ? "'".date( "Y-m-d", $results['article']->publicationDate )."'" : "" ?>);
</script>
while the only bit of server-side code I can imagine causing this error is:
// Parse and store publication date
if ( isset( $params['publicationDate'] ) ) {
$publicationDate = explode ( '-', $params['publicationDate'] );
if ( count( $publicationDate ) == 3 ) {
list ($y, $m, $d) = $publicationDate;
$this->publicationDate = mktime(0, 0, 0, $m, $d, $y);
}
}
Does anyone have any idea what could be causing this? Is it maybe related to the timezone I've set in my config file (America/Toronto)?
Upvotes: 0
Views: 429
Reputation: 54022
it may be problem of month
if it is then solution is below:
The value returned by getMonth
is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.
so to get the current month you always need to write +1
like this
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;//January is 0!
Upvotes: 0
Reputation: 292
Try setting the time in mktime to noon or something instead of 00:00:00 -- and you should explicitly declare a timezone anyway, as good practice. If it's consistently one day out, you can definitely do $d+1 in the mktime statement as suggested by @diEcho (but you said it was the date that was out, not the month, and I do believe that date is 1-indexed not 0 - but if it's consistently wrong, you can make it consistently fixed).
Upvotes: 1