We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    You’d need to break the string to get the date portion

    $whole_string = explode(' ',$v_LastUp)
    //then break up the first part of the string
    $date_strings = explode('/',$whole_string[0]);
    //then rebuild the date
    $new_date = $date_string[1].'/'.$date_string[0].'/'.$date_string[2];
    //then rebuild the whole string:
    $v_LastUp = $new_date.' '.$whole_string[1];
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 4192
      • 43 Posts
      Thanks to your help the date is now displayed like this:

      09/03/2006 06:45:

      Do you have any idea on how can I add a+7 hours difference to the total, getting rid also of the final :, so the date/hour could be like this:

      09/03/2006 13:45

      Thank you so much!
        • 4192
        • 43 Posts
        OK, I’m getting nearer: Using this code:
        $whole_string = explode(' ',$v_LastUp);
        
        //then break up the first part of the string
        $date_string = explode('/',$whole_string[0]);
        $fuso = explode(':',$whole_string[0]);
        
        //then rebuild the date
        $new_date = $date_string[1].'/'.$date_string[0].'/'.$date_string[2];
        $new_fuso = $date_string[0].':'.$date_string[1];
        
        //then rebuild the whole string:
        $v_LastUp = $new_date.' alle ore '.$new_fuso;
        

        I succeeded in getting the data like this: 09/03/2006 alle ore 07:45.
        But I still don’t know how to add the time zone difference.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I have the funny feeling that there are php functions to deal with all of this...I’ll poke around in the php documentation and see what I can find.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4192
            • 43 Posts
            Quote from: sottwell at Mar 09, 2006, 12:36 PM

            I have the funny feeling that there are php functions to deal with all of this
            Did you find anything about it?
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Not yet, but there’s a lot of mysql and php documentation to dig through.

              I did find some interesting material here, especially in the comments:

              http://il2.php.net/manual/en/function.strtotime.php

              In fact, it looks like you can convert the date/time string you get using strtotime(’string’), then set your locale, then use strftime on the timestamp that produces to get the date/time string you want. There are also functions for dealing with gmt, and in php 5 functions for dealing with timezones. There is a lot of information on handling date and time there, and the comments are also well worth reading.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 31337
                • 258 Posts
                Look at the PHP functions for:
                date_default_timezone_get
                date_default_timezone_set

                Use the latter to set it to the user’s preferred time zone, and then the rest of your code can work unmodified
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Those two functions are new to PHP 5 only.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 31337
                    • 258 Posts
                    Quote from: sottwell at Mar 12, 2006, 07:20 PM

                    Those two functions are new to PHP 5 only.

                    Ugh....you’re right, I missed that. Sorry.

                    The other way to do it (although it feels horribly hack-ish to me) is to set the TZ environment variable to the right zone and that way the date/time will offset properly from the local server
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      or, which is even more hackish, since you know where the feed is coming from, add (or subtract, I can never remember which way it goes) the appropriate value from the original once you convert it from the string to a timestamp, then convert it back to your localized string.

                      This original date/time value is coming from an RSS feed in the US, which is what causes it to need to be converted in the first place.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org