Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder durangod's Avatar
    Join Date
    Nov 2010
    Location
    East Texas USA
    Posts
    2,068
    Thanks
    349
    Thanked 57 Times in 55 Posts

    subtract the php date [P] option difference from the date value

    Hi,

    I know what the difference is, its -6 but i dont want that to show in the display using P, i would rather just have the date output reflect the local tz difference.

    so far i have

    PHP Code:

         
    if (date_default_timezone_get()) 
            {    
              
    $tz date_default_timezone_get();
             }


            if (
    ini_get('date.timezone')) 
            {
             
    $tz ini_get('date.timezone');
            }


             
    $date = new DateTime("@".$bans->banstamp); //UTC
             
    $date->setTimezone(new DateTimeZone($tz));
             
    $banstampconvert $date->format('Y-m-d H:i:s'); 
    what i would like to do is just take -6 or whatever the tz is off of the $banstampconvert value so it displays proper local value. it would be nice if i could store the P value then i could just subtract that from the timestamp (in seconds) before the conversion.
    Last edited by durangod; Aug 1st, 2016 at 06:03 AM.

  2. #2
    Senior Coder durangod's Avatar
    Join Date
    Nov 2010
    Location
    East Texas USA
    Posts
    2,068
    Thanks
    349
    Thanked 57 Times in 55 Posts
    how the heck did i get in mysql lol.. moderator sorry please move this to php section, dang

    i think this might be what i need

    PHP: DateTimeZone::getOffset - Manual

    i just had to find the right search term to use


    here is how i did it



    PHP Code:

            
    if (date_default_timezone_get()) 
            {    
              
    $tz date_default_timezone_get();
             }


            if (
    ini_get('date.timezone')) 
            {
             
    $tz ini_get('date.timezone');
            }


                 
    //first lets get the offset
                 
    $date = new DateTime("@".$bans->banstamp); //UTC
                 
    $date->setTimezone(new DateTimeZone($tz));          
                 
    $offset $date->getOffset();//the difference - or + in seconds

                 //now lets set the new timestamp value
                
                 
    if($offset 0)
                 {

                  
    $freshstamp $bans->banstamp $offset;

                  }else{

                         
    $freshstamp $bans->banstamp $offset;

                         }
    //close else offset


                 //Now lets convert the banstamp to ymd hms display for admin
                 
    $banstampconvert date('Y-m-d H:i:s',$freshstamp); 
    Last edited by durangod; Aug 1st, 2016 at 08:21 AM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •