0

I receive this datetime 190522000000Z (ISO8601). I need to get servers local datetime to ISO8601 and see the diference in number of days. I tried some php functions but am lost - this post was helpful but did not work for my case How to calculate the difference between two dates using PHP?

//now on local server
$datetime1 =  date('c');

$now = $datetime1 ;
$your_date = '190522000000Z';
$datediff = $now - $your_date;

error_log(print_r( round($datediff / (60 * 60 * 24))  , true));

I'm unable to get how many days have passed (the difference)

  • 2
    That's not a valid formatted date. What date is that supposed to be, and where are you getting it from? – aynber Aug 22 '19 at 18:53
  • Hi @aynber I get a cert from Amazon , I then parse it via "openssl_x509_parse", I then go to "validTo" node which comes in as a value of 200515120000Z . I then need to get my local server date/time to see if the cert is still valid – dacosta_rafael Aug 22 '19 at 19:24
  • 1
    Agreed, `date('c')` should be ISO8601, something like "2004-02-12T15:19:21+00:00", but I'm not familiar with the format of "190522000000Z". If it's "200515120000Z", then the format might be "YdmHi". – showdev Aug 22 '19 at 19:26
  • `200515120000Z` looks closer to a proper date without dashes/spaces/colons. It would be a format of `YmdHis\Z`, if you want to use the [`DateTime::createFromFormat()`](https://www.php.net/manual/en/datetime.createfromformat.php) function. The DateTime class also has options for calculating differences. – aynber Aug 22 '19 at 19:29

1 Answers1

0

If the format in your question is "YYYYDDMMHHIIZ", then month data seems invalid: "00".
But the string you've shown in a comment includes a potential date in that format:

  • 2005 - year
  • 15 - day of month
  • 12 - month of year

So, December 15, 2005.
That's followed by four digits (possibly hours and minutes) and the "Z" character:

If the time is in UTC, add a Z ... sometimes referred to as "Zulu time" (ISO8601 UTC)


Assuming that format:

date_default_timezone_set('UTC');

$now = new DateTime();
$old = DateTime::createFromFormat('YdmHi\Z', '200515120000Z');

echo $old->format('c')
  . ' to ' . $now ->format('c')
  . ' is ' . $old->diff($now)->format('%R%a days.');

2005-12-15T00:00:00+00:00 to 2019-08-22T20:10:29+00:00 is +4998 days.

showdev
  • 28,454
  • 37
  • 55
  • 73
  • cool @showdev got past that with your help but still lost on point 6 of https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-a-web-service.html#manually-verify-request-sent-by-alexa – dacosta_rafael Aug 26 '19 at 22:59