Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8162023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:37:16+00:00 2026-06-06T18:37:16+00:00

I am adding auction-based data to my system. For example: user’s timezone is :

  • 0

I am adding auction-based data to my system. For example:

user's timezone  is : `America/Denver`
auction start time is : Thu, 21 Jun 2012 03:46:22 AM
auction period : 1 day.
auction end time : Fri, 22 Jun 2012 03:46:22 AM

I store all these information as it is in my DB (i.e. all stored time based on user’s timezone).

Now I want the actual difference between end time and current time (of America/Denver timezone).

I used DateTime() functions

so even I don’t convert the timezone; it returns same difference (and that is wrong too).

My PHP code is below; you can also find it at CodePad

$end_time = 'Fri, 22 Jun 2012 03:46:22 AM';
$tz = 'America/Denver';
dateDifference($end_time,$tz);

function dateDifference($end, $tz = NULL)
    {
      $owner_tz = new DateTimeZone($tz);
      //var_dump($owner_tz->getName()); 

      $from  = new DateTime("now", new DateTimeZone('GMT'));     
      $from ->setTimeZone($owner_tz);

      $to = new DateTime($end,new DateTimeZone('GMT'));
      /* @Note:I have commented below setTimeZone() because I have already stored 
       * `end time` as per user's  timezone, So I dont need to convert it again 
       * into user's timezone.you can un-comment below line. 
       * it doesn't affect the results anyways.
       */
     //$to ->setTimeZone($owner_tz);        

    //procedural style using date_diff()
    $interval = date_diff($from, $to);        
    var_dump($interval); 

    // OO style using dateTime::diff()
    $interval = $from->diff($to);       
    var_dump($interval);     
}

Returns:

object(DateInterval)[4]
  public 'y' => int 0
  public 'm' => int 0
  public 'd' => int 0
  public 'h' => int 16
  public 'i' => int 40
  public 's' => int 24
  public 'invert' => int 0
  public 'days' => int 6015

References:

  • DateTime()
  • DateTime::diff
  • DateTime::setTimeZone
  • Handling timezone conversion with PHP DateTime
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:37:17+00:00Added an answer on June 6, 2026 at 6:37 pm

    I got the solution, so i would like to share

    Actually I have set default timezone in config.inc.php file as below

    date_default_timezone_set('America/Los_Angeles');

    then I check the current time and timezone of MySQL server from phpmyadmin with below query

    SELECT NOW(), SYSDATE(), @@global.time_zone , @@session.time_zone , 
          TIMEDIFF( NOW( ) , CONVERT_TZ( NOW( ) , @@session.time_zone ,  '+00:00' )) 
          AS OFFSET
    

    This return the OFFSET value +05:30

    solution steps:

    • First I changed the timezone of mySQL Server to GMT/UTC +00:00 ( I have super privilage on mySQL server)

      SET GLOBAL time_zone = '+00:00';  
      
    • We save the date and time using start_date = NOW() ( column datatype: DATETIME )

    Now there is 2 way to get date and time as per user’s timezone (America/Denver)

    first method ( using PHP DateTime)

     /*
       * first set timezone as GMT.
       * This is MUST because default timezone is differ from user timezone  
      */     
        $gmt = new DateTimeZone('GMT');
        $user_tz = 'America/Denver';
        $st = new DateTime($row[`start_date`], $gmt);
        // now set user timezone
        $st->setTimezone($user_tz );
        $stime = $qt->format('r');
        echo $stime;
    

    second method (using MySQL UNIX_TIMESTAMP)

    #$retrieve data from server in timestamp
    $qry = "SELECT `start_date`,UNIX_TIMESTAMP(`start_date`) AS sTimestamp FROM..."  
    $st = new DateTime('@'.$row['sTimestamp ']);                     
    $stime = $st->format('r');
    echo $stime;
                      
    

    Note : dont change start_date to timestamp with strtotime(). It will return different value from the UNIX_TIMESTAMP()
    i.e.

     strtotime($row['start_date']) !== $row['sTimestamp']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am adding a auction section to my website , i can easily make
We're using a FileStreamResult to provide video data to a Silverlight MediaElement based video
I'm attempting to build a window-based application system (a mini GUI, if you will)
When adding a new Dataset to a report based off a stored procedure that
I have developed a normal browser-based Rails game application. I'm now adding CloudMailin to
I'm implementing system which uses role based access to different methods in classes. For
I'm having trouble adding any data to my database. It lets me modify entries
Adding more and more configurations to my servlet container ( Embedded Jetty in my
Adding more than one child to a WPF StatusBar results in poor layout with
Adding Exceptional Handling is a good practise, but I have a doubt, In our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.