[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

11/1/2011 9:02:00 PM

Windows, at least from XP on, (don't have access to before XP) has a
Date Time format that the user can set for Short Time and Long Time.

Regional and Language Options
Customize

Seems that Short Time appears in Windows Explorer and also when
FindFirst then DateSerial and Format$ converts. See code below.
The Format$ does not produce what I expect.

Instead of the explicit / I use, the Format$ returns ,
e.g. 2011, 10, 12 22:46:58
And yes, that 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.

So what is the best way to get time returned correctly into a VB6
String variable say "YYYY/MM/DD HH:NN:SS" ?

Private Function GetFileTime(ByRef FTime As FileTime) As Date

Dim tSTime As SYSTEMTIME

If FileTimeToSystemTime(FTime, tSTime) <> 0 Then
With tSTime
GetFileTime = DateSerial(.wYear, .wMonth, .wDay) +
TimeSerial(.wHour, .wMinute, .wSecond)
End With ' tSTime

Else ' Problem
RaiseDllErr Err.LastDllError, "GetFileTime", "GetFileTime
failed"
GetFileTime = Now ' pass any date

End If

End Function 'GetFileTime

Private Function GetFileTimeFmt(ByRef FTime As FileTime) As String

GetFileTimeFmt = Format$(GetFileTime(FTime), "YYYY/MM/DD HH:NN:SS")

End Function 'GetFileTimeFmt


19 Answers

Dianne Kaminsky

11/2/2011 3:36:00 AM

0

> I need the date time in a sortable format and the format I specify
> regardless of what Windows wants to return.
>
Why use the format function at all to get the dates sorted in
chronological order, just leave it as a "Date" variable which
inherently gives you the proper order.
Then use the format function only for displaying / printing the item.


> So what is the best way to get time returned correctly into a VB6
> String variable say "YYYY/MM/DD HH:NN:SS" ?

The format string you show above is perfectly fine.

I hope I helped you out, otherwise I guess I just don't follow your
problem.

Duke

>
>
> Private Function GetFileTimeFmt(ByRef FTime As FileTime) As String
>
>     GetFileTimeFmt = Format$(GetFileTime(FTime), "YYYY/MM/DD HH:NN:SS")
>
> End Function 'GetFileTimeFmt

BeeJ

11/4/2011 2:00:00 AM

0

Dianne Kaminsky pretended :
>> I need the date time in a sortable format and the format I specify
>> regardless of what Windows wants to return.
>>
> Why use the format function at all to get the dates sorted in
> chronological order, just leave it as a "Date" variable which
> inherently gives you the proper order.
> Then use the format function only for displaying / printing the item.
>
>
>> So what is the best way to get time returned correctly into a VB6
>> String variable say "YYYY/MM/DD HH:NN:SS" ?
>
> The format string you show above is perfectly fine.
>
> I hope I helped you out, otherwise I guess I just don't follow your
> problem.
>
> Duke
>
>>
>>
>> Private Function GetFileTimeFmt(ByRef FTime As FileTime) As String
>>
>>     GetFileTimeFmt = Format$(GetFileTime(FTime), "YYYY/MM/DD HH:NN:SS")
>>
>> End Function 'GetFileTimeFmt

The sortable date is stored as a type String, period.

The format string does not work as shown and returns the Windows format
regardles of what I put.

For now, I am using the FileTimeToSystemTime(FTime, tSTime)

and rewriting the sub to provide the format directly.

Format$(.wYear, "00") & "/" & ...

Was hoping there is a system API that provides a faster method.
This code is part of a long loop that is time consuming and obvious to
the user, and I want to speed it up as much as possible.


Mike Williams

11/4/2011 10:26:00 AM

0

"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







BeeJ

11/4/2011 2:04:00 PM

0

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.


Dee Earley

11/4/2011 2:13:00 PM

0

On 04/11/2011 10:25, Mike Williams wrote:
> 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")

They can also be quoted:
s1 = Format$(Now, "yyyy""/""mm""/""dd Hh"":""Nn"":""Ss")

(More useful when using longer literals.)

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Mike Williams

11/4/2011 4:33:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:j90rdj$mlg$1@dont-email.me...

> Raining hard right now so I have to go watch. Love the rain.

Yep. So do I. In fact I love a really good old thunder and lightning storm
even better. Nature at its best!

Mike


BeeJ

11/4/2011 10:36:00 PM

0

Deanna Earley explained :
> On 04/11/2011 10:25, Mike Williams wrote:
>> 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")
>
> They can also be quoted:
> s1 = Format$(Now, "yyyy""/""mm""/""dd Hh"":""Nn"":""Ss")
>
> (More useful when using longer literals.)

Another nuance. Thanks. Still, what is the significance of the capital
H in Hh etc.


ralph

11/5/2011 12:10:00 AM

0

On Fri, 04 Nov 2011 15:35:51 -0700, BeeJ <nospam@spamnot.com> wrote:

>Deanna Earley explained :
>> On 04/11/2011 10:25, Mike Williams wrote:
>>> 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")
>>
>> They can also be quoted:
>> s1 = Format$(Now, "yyyy""/""mm""/""dd Hh"":""Nn"":""Ss")
>>
>> (More useful when using longer literals.)
>
>Another nuance. Thanks. Still, what is the significance of the capital
>H in Hh etc.
>

h := hours in am/pm (0-12)
H := hour in 24-hour (0-23)
a := am/pm tag (AM-PM)
(sometimes a = "am/pm", A = "AM/PM")

The following character is often not needed. Thus "Hh" is all that is
needed to distinguish from "hh". Occasionally just "h" or "H" is
sufficient.

[Actual libraries often vary. I use so many different 'Format'
functions I hesitate to state exactly what VB6 accepts or doesn't
accept. But you can test quick enough.]

-ralph

Bob Butler

11/5/2011 2:11:00 AM

0


"ralph" <nt_consulting64@yahoo.net> wrote in message
news:bsu8b7ho9gapfljfjos8a035et9ncviusk@4ax.com...
<cut>
> h := hours in am/pm (0-12)
> H := hour in 24-hour (0-23)

I don't think so, at least for VB... I can only get 24-hour format if I
don't include the am/pm specification. Bothe H and h do the same thing as
far as I can tell.

> The following character is often not needed. Thus "Hh" is all that is
> needed to distinguish from "hh". Occasionally just "h" or "H" is
> sufficient.

The single H or h displays hours without leading zeros; the pair always
displays 2 digits:
?format$(#4:00AM#,"H:nn")
4:00
?format$(#4:00AM#,"HH:nn")
04:00


> [Actual libraries often vary. I use so many different 'Format'
> functions I hesitate to state exactly what VB6 accepts or doesn't
> accept. But you can test quick enough.]

yep

ralph

11/5/2011 3:32:00 AM

0

On Fri, 4 Nov 2011 19:11:04 -0700, "Bob Butler"
<bob_butler@cox.invalid> wrote:

>
>"ralph" <nt_consulting64@yahoo.net> wrote in message
>news:bsu8b7ho9gapfljfjos8a035et9ncviusk@4ax.com...
><cut>
>> h := hours in am/pm (0-12)
>> H := hour in 24-hour (0-23)
>
>I don't think so, at least for VB... I can only get 24-hour format if I
>don't include the am/pm specification. Bothe H and h do the same thing as
>far as I can tell.
>
>> The following character is often not needed. Thus "Hh" is all that is
>> needed to distinguish from "hh". Occasionally just "h" or "H" is
>> sufficient.
>
>The single H or h displays hours without leading zeros; the pair always
>displays 2 digits:
>?format$(#4:00AM#,"H:nn")
>4:00
>?format$(#4:00AM#,"HH:nn")
>04:00
>

Dop!

Thanks for catching that. I flat forgot about leading zeros.

My only excuse is like I said, I use too many different libraries,
although two chars for forcing zeros is pretty consistent, thus my
excuse is pretty lame in any language. <g>

Another lesson learned - well, actually a lesson I've been taught more
than once, but never seem to remember - don't reply unless you can
test it.

I write so little VB6 these days.

-ralph