DateAdd different result in India than US recently

Posted on 2008-11-12
Last Modified: 2013-11-19
We have a corporate site that has been in use in the US for a long time and now in the last few months employees in India have begun to use it.

The code in question uses the vbscript DateAdd function to add 90 days to the current date. It worked until this week (I don't have an exact date for the start of the problem) as expected in both the US and in India, that is, it would add 90 days properly. Now, it works in the US but in India the resultant date is 81 days out instead of 90.

E.g., Today an Indian user visited the site and got an expiration date of February 1, 2008. It should be February 10th.

Is there an explanation for this sudden change?

(I know we've had the Day Light Savings time change in the US but that doesn't seem to have any bearing on this...a 9 day discrepancy!)

<% 'Figure out what the default expiration date should be 

		      ' 90 days for a Temporary badge, 1 year for Contractor 

			  sTodaysDate = Date

			  response.write "Date = " & 	sTodaysDate		  

			  'DateAdd will Compensate for Leap Day

			  If (InStr(UCase(rsPerson.Fields.Item("person_type_description").Value), "TEMPORARY") > 0) Then

			    'This is a Temporary, set default date to 90 days in future

					sExpDate = DateAdd("d", 90, sTodaysDate)


			  	'This is a Contractor, set default date to 1 year in future

				'DateAdd will Compensate for Leap Day

					sExpDate = DateAdd("yyyy", 1, sTodaysDate)				

			  End If


			sDefaultMonth = Month(sExpDate)

			sDefaultDay = Day(sExpDate)

			sDefaultYear = Year(sExpDate)


Open in new window

Question by:BlueKarana
    LVL 15

    Accepted Solution

    Most likely this is an internationalization issue with one of the functions you are using.   I'm not finding which one quickly.   If you can, find out what the locale is set to for the India users and try to reproduce it by changing your local settings to that local.

    My guess is that by assigning Date to sTodaysDate, it's formatting it based on the locale, which is part of what is causing you problems,  If you pass Date in to the DateAdd function it may work better.


    Author Closing Comment

    I think you're on to something. It turns out I missunderstood the person who told me about this. The problem is actually in the form validation with a call to DateDiff. Same problem though.

    This is the call:

    DateDiff("d", SysDate, sDate)

    The variables values look like this going in: DateDiff("d", "11/12/2008", "2/10/2009")

    For a regional setting of United States the result is 90, for Germany it is 295. DateDiff obviously uses the date format specified in the local regional setting internally. This code is called after submit so it's performed locally, not server-side so it makes sense that this would happen. (The person in India has gone home for the night so I just picked a region I know is DD/MM/YYYY.)

    Next I need to figure out how to make this more globally aware...

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now