I've noticed that in JavaScript, when creating a Date, months are zero based.
So I input (from a mysql php call) a value like "2019, 1, 1". I get this value via:
date("Y, m, d",strtotime($mysqlcall['recorded']))
So input that value:
var foo = new Date(2019, 1, 1)
but it produces February 1st 2019. How can I fix that problem?
1 Answer 1
Use the DateTime class:
<?php
$date = new DateTime('2020-01-01 00:00:00'); // Happy new year!
$month = $date->format('m') - 1;
echo $date->format('Y-' . $month . '-d H:i:s');
answered Dec 23, 2019 at 15:49
delboy1978uk
12.4k2 gold badges25 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
delboy1978uk
glad i could help!
default
date('Y, m-1, d', strtotime($mysqlcall['recorded']))