Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
Converting date from JSON response in PHP

I am getting the following date format from a JSON response and want to format it better, but I am a little unsure how to.

Current Response: Wed Mar 02 03:00:00 +1100 2016

Required Response: 2nd of March 2016

Current PHP for output:

$purchase_data['verify-purchase']['supported_until']
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

some speacial formatting here, but possible when reading the manual. also take care of time zone…

<?php

//custom function
function reformatDate( $old, $correction ) {
    // makes it a number of seconds since 1970…
    $old_date_timestamp = strtotime( $old ); 
    //formats again as string
    return date( 'jS F Y', $old_date_timestamp + $correction ); 
}

//Input: Wed Mar 02 03:00:00 +1100 2016
//timezone needs to be taken care of
print reformatDate(
  "Wed Mar 02 03:00:00 +1100 2016", //here you put your input variable
  11*60*60 // here 11h, but maybe the difference of timezones needs to be changed – only you will know after edge cases ;)
);
//desired output: 2nd of March 2016 – check

?>

to do it even better you could ask your own timezone from the local setting. date can help you there as well, or you go by timezone_offset_get to automate that … the latter is more tricky as it raises an error when not set before.

over 4 years ago · Santiago Trujillo Report

0

Try this out:

$old_date_timestamp = strtotime($purchase_data['verify-purchase']['supported_until']);
$new_date = date('d F Y', $old_date_timestamp);
print $new_date;
over 4 years ago · Santiago Trujillo Report

0

Someone posted an answer on here but for some reason was deleted, however i used some of their solution and adapted and created into a function so for anyone else needing to handle a returned date formatted in such a way here is what i done.

function dateFormat($date){
    $current_date = $date;
    return date("jS", strtotime($current_date) ) . ' of ' . date("F Y", strtotime($current_date) );
}

Then called it like so....

dateFormat($purchase_data['verify-purchase']['supported_until']);

Output went from:

Wed Mar 02 03:00:00 +1100 2016

To:

1st of March 2016

Actually noticed now writing this, it is rounding off to 1st rather than 2nd?

UPDATED

Updated with answer from @vv01f to correct the date, here is the final result

function dateFormat( $old, $correction ) {
    $old_date_timestamp = strtotime( $old );
    return date( 'jS F Y', $old_date_timestamp + $correction );
}

Calling it like so...

dateFormat($purchase_data['verify-purchase']['supported_until'], 11*60*60); 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!