[CLOSED] Different time zone settings on DateFields

  1. #1

    [CLOSED] Different time zone settings on DateFields

    I have two date fields and I?m trying to get the difference between the dates (in days). When I enter start date before November 7, 2010 and end date after it I get a number that is not an integer.

    It appears that dates are using different time zone settings: start date is in "Central Daylight Time" and end date is in "Central Standard Time", so I get an extra hour that messes up my calculation. You can see that both date fields are declared in the same manner so I would expect them to use the same time zone settings.

    This looks like a bug. Can this be fixed? Is there a property in ext:DateField that disregards or specifies time zone?

    Here is my code:

    <script type="text/javascript">
            //get date difference in days
            function getDateDiff() {
                var start_date = Ext.getCmp('dtStart').getValue();
                var end_date = Ext.getCmp('dtEnd').getValue();
                alert((end_date - start_date) / (1000 * 60 * 60 * 24) + ' - start date offset: ' + start_date.getGMTOffset() + ', end date offset: ' + end_date.getGMTOffset());
            }
        </script>
    
        <ext:DateField ID="dtStart" runat="server"></ext:DateField>
        <ext:DateField ID="dtEnd" runat="server"></ext:DateField>
    
        <ext:Button runat="server" Text="Get Difference">
            <Listeners>
                <Click Handler="getDateDiff()" />
            </Listeners>
        </ext:Button>
    Thanks,
    George
    Last edited by Daniil; Nov 04, 2010 at 10:36 PM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi,

    This is not a defect.

    You are getting a one offset because the Daylight Saving Time change happens on November 7, 2010 at 2 a.m (in the USA).

    Is there a property in ext:DateField that disregards or specifies time zone?
    No, but you can convert all your DateTime values to UTC.
    Geoffrey McGill
    Founder
  3. #3
    If you add Datejs (http://www.datejs.com/) to your project, there is a "TimeSpan" module which can be included.

    The TimeSpan module will then calculate offsets.

    Example

    var start = Date.parse("nov 7 2010");
    var end = Date.parse("nov 8 2010");
    
    new TimeSpan(end - start).days
    Geoffrey McGill
    Founder
  4. #4
    You'll run into the opposite problem in the spring, where you'll have less than 24 hours diff.

    You should be able to work around all these problems by just adding one hour to the end date, then calling Math.round() with the difference.

    Hope this helps.
    Last edited by geoffrey.mcgill; Nov 04, 2010 at 1:38 AM.
    Geoffrey McGill
    Founder
  5. #5
    I think the following should work.

    Example

    var start_date = dtStart.getValue();
    var end_date = dtEnd.getValue().add(Date.HOUR, 1);
    
    alert(Math.round((end_date - start_date) / (1000 * 60 * 60 * 24)));
    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] [1.2] DateFields in daterange
    By FVNoel in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 05, 2012, 3:42 PM
  2. Replies: 2
    Last Post: Mar 28, 2012, 1:39 PM
  3. [CLOSED] V2.0 DateFields with DateRange
    By Aurelio in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 16, 2012, 4:17 PM
  4. [CLOSED] Time zone for time in UTC
    By krzak in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jun 01, 2011, 1:56 PM
  5. Replies: 4
    Last Post: Apr 25, 2011, 8:35 AM

Tags for this Thread

Posting Permissions