-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
  • 169,008
  • 28
  • 173
  • 236
ahmad
  • 53
  • 7

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
  • 2,993
  • 2
  • 22
  • 43