Home > Archive > Visual Basic Syntax > March 2005 > Dates in VB and international formats
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Dates in VB and international formats
|
|
|
| I'm having some big problems with dates in different formats.
Let me explain.
For my app you can get a time-limited registration code. Within the code I
store the date that the code was created.
Example:
D2005Mar03
Meaning the code was generated on March 3rd 2005
Within my app I validate the code and check if you're still within the
hardcoded timelimit, based on the date within the code and the current date.
Now the current date I get it from the machine running my app, this means it
could be in any date format.
I can convert the current date (given in whatever format) to an common
format like:
30-Mar-2005 (dtoday)
And the date from the code I can convert it to
03-Mar-2005 (dfromcode)
If I do a DATEDIFF("d",dfromcode,dtoday) I should get the number of days the
code is "old".
If I do this on a system with my internation settings set to English (US) it
works fine, if a user in Germany does this, you get a TYPE MISMATCH on the
DATEDIFF line.
Any thought on this?
dirk.
| |
| Bob Butler 2005-03-30, 4:01 pm |
| "Dirk" <dirk@nospam_to_remove_ofcourse.woodstone.nu> wrote in message
news:uakt2kUNFHA.3156@TK2MSFTNGP15.phx.gbl
<cut>
> If I do this on a system with my internation settings set to English
> (US) it works fine, if a user in Germany does this, you get a TYPE
> MISMATCH on the DATEDIFF line.
>
> Any thought on this?
Don't use month names; "Mar" is not a valid month abbreviation in German.
try using yyyy-mm-dd format instead of yyyy-mmm-dd
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| Rick Rothstein 2005-03-30, 4:01 pm |
| > For my app you can get a time-limited registration code. Within the
code I
> store the date that the code was created.
> Example:
> D2005Mar03
> Meaning the code was generated on March 3rd 2005
>
> Within my app I validate the code and check if you're still within the
> hardcoded timelimit, based on the date within the code and the current
date.
>
> Now the current date I get it from the machine running my app, this
means it
> could be in any date format.
>
> I can convert the current date (given in whatever format) to an common
> format like:
> 30-Mar-2005 (dtoday)
>
> And the date from the code I can convert it to
> 03-Mar-2005 (dfromcode)
>
> If I do a DATEDIFF("d",dfromcode,dtoday) I should get the number of
days the
> code is "old".
>
> If I do this on a system with my internation settings set to English
(US) it
> works fine, if a user in Germany does this, you get a TYPE MISMATCH on
the
> DATEDIFF line.
Since you have a standardized format for your stored dates, you can
generate a date value quite easily using the DateSerial function.
Dim StoredDate As String
Dim DateValueForStoredDate As Date
......
......
StoredDate = "D2005Mar03"
DateValueForStoredDate = DateSerial(CLng(Mid$(StoredDate, 2, 4)), _
Month(Mid$(StoredDate, 6, 3) & " 1, 2005"), _
CLng(Right$(StoredDate, 2)))
......
The DateValueForStoredDate variable is of type Date, you can use it
anywhere a date value is needed.
Rick - MVP
| |
| Rick Rothstein 2005-03-30, 4:01 pm |
| Bob raises a good point about the month abbreviation and language
applicability. You can still use the format you have chosen, we just
need to modify my suggested code to allow for it on anyone's system....
Dim MonthNum As Long
Dim Months As String
Dim StoredDate As String
Dim DateValueForStoredDate As Date
Months = "JanFebMarAprMayJunJulAugSepOctNovDec"
......
......
StoredDate = "D2005Mar03"
MonthNum = CLng(1 + (InStr(1, Months, _
Mid$(StoredDate, 6, 3), vbTextCompare) - 1) / 3)
DateValueForStoredDate = DateSerial(CLng(Mid$(StoredDate, 2, 4)), _
MonthNum, CLng(Right$(StoredDate, 2)))
......
However, if you are not locked into the stored date format yet, I'd
consider changing it in accordance with Bob's posting.
Rick - MVP
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:%23EyK43UNFHA.2580@TK2MSFTNGP09.phx.gbl...
> code I
the[color=darkred]
current[color=darkred]
> date.
> means it
common[color=darkred]
> days the
> (US) it
on[color=darkred]
> the
>
> Since you have a standardized format for your stored dates, you can
> generate a date value quite easily using the DateSerial function.
>
> Dim StoredDate As String
> Dim DateValueForStoredDate As Date
> .....
> .....
> StoredDate = "D2005Mar03"
> DateValueForStoredDate = DateSerial(CLng(Mid$(StoredDate, 2, 4)), _
> Month(Mid$(StoredDate, 6, 3) & " 1, 2005"), _
> CLng(Right$(StoredDate, 2)))
> .....
>
> The DateValueForStoredDate variable is of type Date, you can use it
> anywhere a date value is needed.
>
> Rick - MVP
>
| |
|
| Well I'm locked to the stored format.
And what I did do after some more testing (already was testing a day :-() I
wrote something similar to what you proposed, using the dateserial.
Thanks for the help
dirk.
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:%23FBKwXVNFHA.3192@TK2MSFTNGP10.phx.gbl...
> Bob raises a good point about the month abbreviation and language
> applicability. You can still use the format you have chosen, we just
> need to modify my suggested code to allow for it on anyone's system....
>
> Dim MonthNum As Long
> Dim Months As String
> Dim StoredDate As String
> Dim DateValueForStoredDate As Date
> Months = "JanFebMarAprMayJunJulAugSepOctNovDec"
> .....
> .....
> StoredDate = "D2005Mar03"
> MonthNum = CLng(1 + (InStr(1, Months, _
> Mid$(StoredDate, 6, 3), vbTextCompare) - 1) / 3)
> DateValueForStoredDate = DateSerial(CLng(Mid$(StoredDate, 2, 4)), _
> MonthNum, CLng(Right$(StoredDate, 2)))
> .....
>
> However, if you are not locked into the stored date format yet, I'd
> consider changing it in accordance with Bob's posting.
>
> Rick - MVP
>
>
>
> "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> news:%23EyK43UNFHA.2580@TK2MSFTNGP09.phx.gbl...
> the
> current
> common
> on
>
| |
| Bob Butler 2005-03-30, 9:00 pm |
| "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:%23FBKwXVNFHA.3192@TK2MSFTNGP10.phx.gbl
> Bob raises a good point about the month abbreviation and language
> applicability. You can still use the format you have chosen, we just
> need to modify my suggested code to allow for it on anyone's
> system....
Asuming, of course, that the date gets coded to the string on a system that
uses english month abbreviations and that it's only the decoding back to a
date that has to deal with this. Given that this is a license timeout
scheme it may very be getting coded on user systems as well.
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
|
|
|
|
|