programing software expiry date problem with regional settings

P

PeterEvans

I want to set an expiry date which I am storing in the registry. This
is all working well.

The problem is when someone installs the software, then changes their
location (Australia dd/mm/yyyy to USA mm/dd/yyyy). On startup the
software retrieves the stored date and the days to go are wrong.

I have a work around that works out the daystogo based on hard-coding
the date into code and that is OK for the beta.

Sub workAround()
Dim dateexpire As Date
dateexpire = CDate("April 1, 2009")
Debug.Print System.LanguageDesignation & " dateexpire=" &
dateexpire & " daystogo=" & DateDiff("d", Date, dateexpire)
End Sub

Output in the immediate window
workAround
English (U.S.) dateexpire=4/1/2009 daystogo=45
(change region)
workAround
English (Australia) dateexpire=1/04/2009 daystogo=45

I had tried to use the same strategy to save the expirary date
using
dateexpire = CDate("April 1, 2009")
then saving this and then reading it on startup it does not work as
the date and the month is around the wrong way.

Does anyone have any idea how I can have a general solution that works
in all location and even if people move location. The code is below
and you can download a small word document with the code in it from
http://www.baker-evans.com/community/mod/forum/discuss.php?d=167#p196

Any help gratefully received,
PeterEvans

Sub setExpire()
Dim dateInstalled As Date
Dim dateexpire As Date

dateexpire = CDate("April 1, 2009")
dateInstalled = Date
daystogo = DateDiff("d", Date, dateexpire)

SaveSetting appname:="test", Section:="test", Key:="dateExpire",
setting:=dateexpire
SaveSetting appname:="test", Section:="test",
Key:="dateinstalled", setting:=dateInstalled
Debug.Print System.LanguageDesignation & " date=" & Date & "
DateInstalled=" & dateInstalled & " dateexpire=" & dateexpire & "
daystogo=" & daystogo
End Sub

Sub readExpire()
Dim dateInstalled As Date
Dim dateexpire As Date

dateexpire = GetSetting(appname:="test", Section:="test",
Key:="dateExpire")
dateInstalled = GetSetting(appname:="test", Section:="test",
Key:="dateinstalled")
daystogo = DateDiff("d", Date, dateexpire)

Debug.Print System.LanguageDesignation & " date=" & Date & "
DateInstalled=" & dateInstalled & " dateexpire=" & dateexpire & "
daystogo=" & daystogo
End Sub
 
N

NOPIK

location (Australia dd/mm/yyyy to USA mm/dd/yyyy). On startup the
software retrieves the stored date and the days to go are wrong.


Why don't you simple store date as Date (or, text representation of
the float value) type?
 
P

PeterEvans

The problem is that when i store it as a string it will not get
interpreted correctle if someone changes the location.

The expirary date is April 1 2009 and I tried to set this in the
following way

dateexpire = CDate("April 1, 2009")
SaveSetting appname:="test", Section:="test", Key:="dateExpire",
setting:=dateexpire

But if this is then read after the location has been changed from AU
to US the date comes back as
4/01/2009

I need a way of correctly specifying the April 1 2009 for any
location and then reliably retriving it even if the location has
changed. The code to expereiment with it at
http://www.baker-evans.com/community/mod/forum/discuss.php?d=167#p196


PeterEvans
 
P

Peter Jamieson

Storing it as a string using the format YYYY-MM-DD will probably avoid
ambiguity when you retrieve the value from the registry. However, how ot
ensure that you have the correct month and day for any dates you put in
there may still be a problem.


Peter Jamieson

http://tips.pjmsn.me.uk
 
D

Doug Robbins - Word MVP

Use MMM or MMMM format and then use a routine to convert that back to a
numeric value.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top