0

Hello I need to store a duration (0 à 24h) in my database in the format 1970-01-01T00:00:00.000Z

So how to convert a value, Eg-: 2:00 to 1970-01-01T02:00:00.000Z

I tried this but the date isn't in GMT format

$date   = "1970-01-01T00:00:00.000Z";
$v      = date(DATE_ISO8601, strtotime('+2 hour', strtotime($date)));
$conn->update('measure', array('observence' => $v), array('id_measure' => 34943));

It return : 1970-01-01T03:00:00+0100

What I need : 1970-01-01T02:00:00.000Z

Thanks in advance for any help

Ajith
  • 2,476
  • 2
  • 17
  • 38
fred
  • 23
  • 3
  • Have you read [php.net](https://www.php.net/manual/en/function.date.php)? – Sfili_81 Jan 24 '20 at 09:41
  • A timestamp is just a single specific time, not a range of times (duration) - you'd be better off with 2 columns in the table: *"start_time"* and *"end_time"* – CD001 Jan 24 '20 at 09:42
  • Aside `1970-01-01T03:00:00+0100` and `1970-01-01T02:00:00.000Z` are actually equivalent, just different timezones. – CD001 Jan 24 '20 at 09:44
  • i need to write in data base of an existing script who i can't modify. i agree it's a good format to store an average duration but I have to keep the existing format for backward compatibility – fred Jan 24 '20 at 09:47

1 Answers1

0

You can use custom format "Y-m-d\TH:i:s\.000\Z" instead of DATE_ISO860

Anggara
  • 625
  • 4
  • 8