0

Here's what im trying to do

<?php
    //get time from what user input on post
    $time = $_POST['time'];

 ?>
            <script type="text/javascript">
                 //convert time to utc
                 var convertedDate = dateFormat('<?php echo $time ?>', 'isoUtcDateTime');       
            </script> 
  <?php 
       $query = "INSERT INTO $table (url, time) VALUES ('$url', 'convertedDate');";
        mysql_query($query);
  ?>

I know you can't just place convertedDate in there like that, so what im asking is how would I go about doing the javascript equivalent of what i did with <?php echo $time ?>

brybam
  • 5,009
  • 12
  • 51
  • 93

4 Answers4

2

Format date in PHP, with date() or DateTite object.

If you need to store other items like that, but not sa simple and JS-dependent, you should do a AJAX request to php file to store it, it's simple with jQuery and .ajax()

Piotr Müller
  • 5,323
  • 5
  • 55
  • 82
  • I really liked the nice simple javascript converter I found. I guess you're right i'll just have to covert the date string `07/20/2011 01:13 am` to UTC using php. Any ideas how I might convert a string like that to UTC? – brybam Jul 20 '11 at 09:26
1

If you need to convert date in UTC.

Use gmdate

http://www.php.net/manual/en/function.gmdate.php

Latest PHP time DateTime class can also help you

$time = new DateTime(ew DateTimeZone('UTC'));

Rikesh
  • 26,156
  • 14
  • 79
  • 87
0

You could do it by setting up a second page containing Javascript that takes a URL query and writes the result to the page. Then use cURL to scrape the answer from the PHP.

But don't.

Gausie
  • 4,291
  • 1
  • 25
  • 36
0

Take a look at the following SO question How can I easily convert dates from UTC via PHP? on converting a time to UTC in php.

Community
  • 1
  • 1
Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66