0

i am getting stuck on this problem. i want to do using jquery

window.newdatevalue = '<?php echo date("Y-m-d") ?>';// this date is dynamic

var newdate = window.newdatevalue;

console.log(newdate); // when i print this it give me right result -2017-02-06 

var finaldate = "<?php echo date('d/M/y',strtotime('"+newdate+"'))?>";

console.log(finaldate); // but when i print this it give me wrong result 01/Jan/70 

Can anyone help me what i am doing wrong

5
  • try change finaldate format to "Y-m-d" [ echo date("Y-m-d",strtotime('"+newdate+"')) ] Commented Feb 6, 2017 at 5:27
  • i tried it but its not working @SarangaR Commented Feb 6, 2017 at 5:27
  • 2
    PHP executes on the server, then the server sends the page to the browser, and javascript runs. You can't just inject a javascript variable in PHP, it's too late Commented Feb 6, 2017 at 5:30
  • for change date format see stackoverflow.com/questions/33299687/… Commented Feb 6, 2017 at 5:37
  • I think, you are misunderstanding some principle of server side programming any way I think you hope following answer [ echo date("d/m/Y",strtotime(date('Y-m-d'))); ] or [ echo date('d/m/Y'); ] Commented Feb 6, 2017 at 5:38

1 Answer 1

0

Can try this. It might help you.

window.newdatevalue = '<?php echo date("d-m-Y", strtotime(date("Y-m-d"))); ?>'

console.log(window.newdatevalue);
Sign up to request clarification or add additional context in comments.

4 Comments

where is $originalDate;
updated my answer
i have different date in different day. So i want to place variable in strtotime
what you mean in above... please specify more clearly

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.