BeeJ
11/4/2011 2:04:00 PM
Mike Williams explained :
> "BeeJ" <nospam@spamnot.com> wrote in message
> news:j8pmo6$p4h$1@speranza.aioe.org...
>> Windows, at least from XP on, has a Date Time format that
>> the user can set for Short Time and Long Time. Regional and Language
>> Options : Customize
>> It seems that the [user chosen separator format] appears in
>> Windows Explorer and also when FindFirst then DateSerial
>> and Format$ converts. The Format$ does not produce what
>> I expect . . . . .
>> s1 = Format$(GetFileTime(FTime), "YYYY/MM/DD HH:NN:SS")
>> Instead of the explicit / I use, the Format$ returns [a comma]
>> e.g. 2011, 10, 12 22:46:58 And yes, that [comma etc] is
>> what is shown as the choice in Customize.
>> I need the date time in a sortable format and the format I
>> specify regardless of what Windows wants to return.
>
> The thing is, in your code you are not actually using a literal either for
> your / date seperator or for your : time seperator. In a VB6 User Defined
> time format those two characters actually represent the current system date
> and time seperators, and that is what they will return. That is why you are
> getting a comma for the date seperator on systems where the user has set his
> system up in such a way. On other systems you might even get a comma, or some
> other character, for the time seperator as well. That is how the VB6 Format
> function works. The function normally regards a character as a literal only
> if that character is not one of the specific formating characters, otherwise
> it regards it as a formatting character. In order to get the VB6 Format
> function to regard any of the normal formatting characters as a literal
> within the format string you need to clearly specify that the character as a
> literal, which you can do using a backslash (although I can understand your
> confusion because that fact is not actually mentioned in the VB6 help files).
> As far as I recall, you definitely want to store the dates as a sortable
> string, in which case to save a little memory you might simply want the date
> and time with no seperators at all, in which case you could use (as an
> example):
>
> Dim s1 As String
> s1 = Format$(Now, "yyyymmddHhNnSs")
>
> If you instead want the literal / for the date seperator and the literal :
> for the time seperator and if you also want a space between the date and the
> time, as it would appear from your post, you could use (as an example):
>
> Dim s1 As String
> s1 = Format$(Now, "yyyy\/mm\/dd Hh\:Nn\:Ss")
>
> The above code would return the format 2011/11/04 10:23:28 regardless of the
> user's Control Panel settings.
>
> Mike
To the resuce again. Thanks Mike.
I did not know that escape characters were valid inside the format
string. Did not even think to try.
Also, is it significant that the time portion has leading upper case
letters. Not seen that before. Will fiddle with that.
I need a representation that Windows/VB6 will know it is a date.
The "hidden" data needs to sort and when displayed, the "hidden" data
will be converted by VB6 code to the format the user selects. Now I
need to add instructions about using escape characters too.
It is amazing all the nuances that I did not come across before.
Raining hard right now so I have to go watch. Love the rain.