-1

With this PHP-code I get the first day of the actual month

date('Y, n, 1')

The output ist

2014, 4, 1

How can I convert it to the Javascript-Date because the Javascript-Date, especially the month is zerobased. That means the output 2014, 4, 1 will be the 1st may 2014.

1
  • You just need to subtract one from the month. What are you wanting to do: create a js variable from a PHP date? Or just get a js variable which is the first day of the current month? Or what?
    – Adam
    Apr 19, 2014 at 17:36

1 Answer 1

0

Try this:

<?php
    $month = date("n");
    $year = date("Y");
    $day = 1;
?>
var myDate=new Date("<?php echo $month?> <?php echo $day?>, <?php echo $year?>");
alert(myDate);

May be this help. JS Date Demo

1
  • Many thanks you gave me an important hint. My solution is now function gd(year, month, day) { return new Date(year, month -1, day).getTime(); } Apr 19, 2014 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.