Karthiga
Karthiga

Reputation: 240

Server Date resolving issue

$eve['start']['dateTime'] = 2013-05-02T14:00:00+05:30;

$current_date = date("m-d-Y",strtotime($eve['start']['dateTime'])); 

$start_time = date("H:i A",strtotime($eve['start']['dateTime']));

when i use the above code am getting it as 05-02-2013 08:30 AM

But i should get 05-02-2013 2:00 PM

why this time difference and shows wrong any idea?

Upvotes: 0

Views: 37

Answers (3)

BLaZuRE
BLaZuRE

Reputation: 2406

The time difference is not wrong. You are getting the correct date and time for a timezone at +0:00. To fix this, set your timezone.

Upvotes: 1

OptimusCrime
OptimusCrime

Reputation: 14863

$eve['start']['dateTime'] = "2013-05-02T14:00:00+05:30"; // Missing quotes in your code?
$current_date = date("m-d-Y",strtotime($eve['start']['dateTime'])); 

Should return 05-02-2013 08:30 AM because your server has timezone sat to GMT+0. If you take 14:00 and subtracts with 5 and a half hour (from +0530 to +0000), it should be 08:30.

To avoid this, you have to set default timezone on your server or in your script.

Upvotes: 0

DevZer0
DevZer0

Reputation: 13535

your formatters seems to be incorrect, to get the desired output use the code below. H is used for 24 hour format with leading zero. h is used for 12 hour format.

date("h:i A");

Upvotes: 0

Related Questions