ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Issues with date/time formatting...

August 15, 2007 11:14pm

Subscribe [3]
  • #1 / Aug 15, 2007 11:14pm

    AussieFreelancer

    72 posts

    Hi all,

    Another issue I am having at the moment is with dates and times. On the site in question, I am inserting into the database using an EE SAEF, and the fields are a date/time format.

    So, when I select 10AM, I insert the entry, and when I look at the entry in the System (edit page), the date shows as 10AM.

    However… when I try to display the time on the website again, I am using php’s date function, and it is showing 00AM

    The same thing happens for all times, in EE edit screen, they display fine, but on the site, they are 10hours out.

    What is the cause of this? Shouldn’t a timestamp be a timestamp? Does it have something to do witht he localization settings? I have checked the system prefs and the timezone is UP8, I have checked my account prefs and the timezone is UP8. I have put in some code to test the server time, local time and user time, and all 3 say UP8.

    If I use date_default_timezone_set(‘Australia/Perth’), the times change to 9 hours out instead of 10. Any help with this would be much appreciated :D

    Thanks

    Patrick

    *edit*

    ok, I have echoed the timestamp as it appears in the database, and I am getting the incorrect time when i put that timestamp into an online converter… so, does EE store the dates in a different format? or will there be a setting somewhere that is causing the errors?

    *edit 2*
    i have just echoed strtotime(‘now’), and put that into the convertor, and that is accurate. So the issue is with pulling it from the database once ee has inserted it. It is inserting the right time, and in the system it shows the right time, so i must be doing something wrong when i pull it out… i am using

    date('Y-m-d H:i s', $row['field_id_21']);

    where $row is pulled from the db…

    * edit 3*
    this is getting more and more weird…

    same time: 10AM entered.

    in the system, it displays 10am. the following code:

    echo '{exp:weblog:entries weblog="timesheet" entry_id="' . $entry_id . '"}EE Time: {ts_start format="%Y-%m-%d %H:%i:%s"}{/exp:weblog:entries}
    
    PHP Time: ' . date('Y-m-d H:i:s', $row['start']) . '';

    displays:

    EE Time: 2007-08-14 08:00:00
    PHP Time: 2007-08-14 00:00:00

    so now i have 3 different times, and the only one correct is the system one.

  • #2 / Aug 16, 2007 9:36am

    AussieFreelancer

    72 posts

    pleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeease? :D any help would be awesome. i have looked through the forums and the wiki and the docs and i cant see what i am doing wrong.

    ok, i may have got the issue down to just two incorrect times now…

    I found out that the server time is actually set to be UP10, even though it is physically located in UP8. So I changed the server time in the admin localization to be UP10, and it appears that that has fixed the EE Front End time issue.

    Site default time zone: UP8
    Server timezone: UP10
    User timezone: UP8

    So now, I just have to deal with the php date function, as the front and back end of EE is displaying correct times using EE code.

    Using php date() still gives me -10 hours out…

  • #3 / Aug 19, 2007 5:06am

    AussieFreelancer

    72 posts

    sorry for the third post, but really need some help with this and I dont think it registers if I just edit it?

    4 days on I am still no closer to a solution, so any advice, thoughts help at all, would be amazing. Just to recap, I have a custom field for the start time, and one for the finish time. These fields are date/time format.

    I am inserting using the EE SAEF, and then displaying using php’s date() function. But the times are totally out and I cant work out why. I have had a look through all the localization settings, and I cant see anything that has helped me so far.

    How am I supposed to use php to display the date? It is stored as unix timestamp isnt it? I am parsing php on input, so I cant use the ee variable to display it, and it isnt possible to display the whole table using EE code as I am performing some calculations on some of the other fields.

    Many thanks in advance,

    Patrick

  • #4 / Aug 20, 2007 9:12pm

    Derek Allard

    3168 posts

    Hey Patrick.

    We aren’t ignoring you, its just that this is a community support forum 😉

    See if this link helps you out http://expressionengine.com/wiki/Dates_Explained/.

  • #5 / Aug 20, 2007 9:21pm

    AussieFreelancer

    72 posts

    haha phew :D was beginning to wonder 😉 I have been able to use a work around on this site in question, as I have the entry id available in php, so to display the dates/times I am using

    {exp:weblog:entries weblog="" entry_id=""}{custom_date format=""}{/exp:weblog:entries}
    which is just a bit more code than
    date('', $custom_field)

    I will have a look at the link, I was looking for something like that but couldn’t find it :D

    Thanks

    Patrick

  • #6 / Sep 24, 2007 8:16am

    AussieFreelancer

    72 posts

    ok, still no joy with these dates, and it has been over a month now, and the client is losing patience fast now. Please can someone help me out here. Nothing I do seems to make any difference. I have tried the localization settings in the config, I have tried heaps of things, but for some reason the date is still 10hrs out.

    The site is hosted on enginehosting, so not sure what timezone that is. I am in WA, Australia, and the site is a WA thing, so the times need to be GMT+8

    I am displaying using EE tags. I am entering into the entry date and expiry date using php strtotime.

    Any help or ideas would be GREATLY appreciated.

    Thanks

    Patrick

  • #7 / Sep 24, 2007 11:50am

    Derek Jones

    7561 posts

    Patrick, EH is Central Standard Time, and is observing DST presently, which you need to set in the Server Localization settings.  You should not be using date() on dates coming from the database, because they are stored as GMT dates relative to the server localization timezone.  You will need to use the Localization class to output correct localized dates.  All of these things must be set and used correctly; welcome to date development nightmares!

  • #8 / Sep 24, 2007 10:59pm

    AussieFreelancer

    72 posts

    haha yeah nightmares indeed… so, I need to manually turn the dst on and off?

  • #9 / Sep 25, 2007 12:03am

    Derek Jones

    7561 posts

    Yes, due to the numerous local rules that different parts of the world have for observation of DST, presently this setting is manual.

  • #10 / Sep 25, 2007 12:17am

    AussieFreelancer

    72 posts

    thats kind of cool though, as there is no dst here, (well except for the stupid trial they have in place), but that then means that I can set it to be the right time here and I wont have to amend it? Sounds like that is a plan…

  • #11 / Sep 25, 2007 9:07am

    Derek Jones

    7561 posts

    No, your Server Localization Settings must match that of the actual location of the server.  You and your users will need to keep your own localization settings correct as well.  If the site can stay on your local time, then in your Member Administration tab of the My Account page, you can check the ‘Use this member’s localization settings as the master site default?’ setting.  But the Server’s Localization Settings need to be accurate.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases