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

marmeladze
  • 6,468
  • 3
  • 24
  • 45
kunal
  • 4,122
  • 12
  • 40
  • 75
  • try change finaldate format to "Y-m-d" [ echo date("Y-m-d",strtotime('"+newdate+"')) ] – SarangaR Feb 06 '17 at 05:27
  • i tried it but its not working @SarangaR – kunal Feb 06 '17 at 05: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 – adeneo Feb 06 '17 at 05:30
  • for change date format see http://stackoverflow.com/questions/33299687/how-to-convert-dd-mm-yyyy-string-into-javascript-date-object – Bharat Dangar Feb 06 '17 at 05: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'); ] – SarangaR Feb 06 '17 at 05:38

1 Answers1

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);
Naincy
  • 2,953
  • 1
  • 12
  • 21