I have a PHP script that outputs an array of data. This is then transformed into
JSON using the
$newticket['ThreadID'] = $addticket; $newticket['Subject'] = $subject; //$newticket['DateCreated'] = date('d-m-Y G:H');
Can anyone help?
You should probably just use a timestamp
$newticket['DateCreated'] = strtotime('now');
// make sure to convert from unix timestamp var now = new Date(dateFromPHP * 1000);
<?php date('c', $yourDateTime); // or for objects $dateTimeObject->format('c'); ?>
documentation says that: format character 'c' is ISO 8601 date (added in PHP 5) example: 2004-02-12T15:19:21+00:00
for more information: http://php.net/manual/en/function.date.php
It is pretty simple.
$formatted_date = $newticket['DateCreated'] = date('Y/m/d H:i:s');
PHP date_format() Function, The date_format() function returns a date formatted according to the specified format. Note: This function does not use locales (all output is in English). Tip: Also � Date Input - Parsing Dates. If you have a valid date string, you can use the Date.parse() method to convert it to milliseconds. Date.parse() returns the number of milliseconds between the date and January 1, 1970:
Is very simple, I'm use this:
new Date("<?= date('Y/m/d H:i:s'); ?>");
An improvement or simplification of @jeremyharris answer would be this one:
DateTime objects in PHP have the
getTimestamp() format, use it and multiply the value by 1000:
2.Our second option is to let MySQL do the work. MySQL has functions we can use to convert the data at the point where we access the database. UNIX_TIMESTAMP will convert from DATETIME to PHP timestamp and FROM_UNIXTIME will convert from PHP timestamp to DATETIME. The methods are used within the SQL query.
The combinations of the year, the month, the day and the separators can be endless. The following are 100 common date text formats and the formulas to convert them into the real dates. After you convert the text into the date format, you can use the format cells method again to transfer to the format you want.
- No, there are multiple ways of instantiating a date object, including a timestamp: w3schools.com/jsref/jsref_obj_date.asp
- @LeeTee The easiest and most transportable format is a timestamp, which you can then convert to whatever you want.
new Date();good answer!
- Ecmascript does not support full ISO 8601. only a simplified version of it
<?=is short for
<?php echo ...
- Thanks man, new thing to me, actually I tried it but I got 500 error maybe cause another error. :)
- Are you just asking for how to format a date in PHP? Go look at the formatting options in the documentation: us.php.net/manual/en/function.date.php