-2

I have date from the server let's say 8/14/2018 12:00pm

I want to get the time only from this date using php and I believe it's easy with date function, but how can I add time to javascript date?

For example if I have in js this date 7/14/2018 I want to add php time 12:00pm with it as one date so it will be like 7/14/2018 12:00pm

Is that possible ?

mplungjan
  • 155,085
  • 27
  • 166
  • 222
ahmad
  • 53
  • 6

1 Answers1

0

Assuming the date in js a string. You could do this

   <?php 
    // define the datetime object
    $dtDate = new DateTime(‘8/14/2018 12:00pm’);
    ?>

    <!— add it to js —>
    <script>
    var dtDate = “7/14/2018”;
    DtDate = dtDate + “ <?php echo $dtDate->format(H:i); ?>”;
    </script>
atoms
  • 3,000
  • 2
  • 19
  • 39