Home All Groups Group Topic Archive Search About

This is driving me crazy!

Author
16 Oct 2005 11:26 PM
Brian
What is the best way to take to string dates and times...

ie.,  10-Oct-2005 10:30:16 AM and 11-Oct-2005 2:17:54 PM

and then determine the number of seconds between these two dates?

I must be missing a simple function to do the conversion...  but I sure
can't seem to find it...

Thanks for the help.

B

Author
16 Oct 2005 11:32 PM
Someone
Debug.Print DateDiff("s", #10-Oct-2005 10:30:16 AM#, #11-Oct-2005 2:17:54
PM#)

Show quoteHide quote
"Brian" <bkstig***@usa.net> wrote in message
news:uh0EKjq0FHA.2652@TK2MSFTNGP14.phx.gbl...
> What is the best way to take to string dates and times...
>
> ie.,  10-Oct-2005 10:30:16 AM and 11-Oct-2005 2:17:54 PM
>
> and then determine the number of seconds between these two dates?
>
> I must be missing a simple function to do the conversion...  but I sure
> can't seem to find it...
>
> Thanks for the help.
>
> B
>
>
Author
16 Oct 2005 11:37 PM
Someone
Use this to convert from a string to a date:

Dim d1 As Date

d1 = CDate(s)


Show quoteHide quote
"Brian" <bkstig***@usa.net> wrote in message
news:uh0EKjq0FHA.2652@TK2MSFTNGP14.phx.gbl...
> What is the best way to take to string dates and times...
>
> ie.,  10-Oct-2005 10:30:16 AM and 11-Oct-2005 2:17:54 PM
>
> and then determine the number of seconds between these two dates?
>
> I must be missing a simple function to do the conversion...  but I sure
> can't seem to find it...
>
> Thanks for the help.
>
> B
>
>
Author
16 Oct 2005 11:42 PM
Brian
aha...
That's what I was missing...  DateDiff!  got it now.  thanks.


Show quoteHide quote
"Someone" <nob***@cox.net> wrote in message
news:uCzSQqq0FHA.2076@TK2MSFTNGP14.phx.gbl...
> Use this to convert from a string to a date:
>
> Dim d1 As Date
>
> d1 = CDate(s)
>
>
> "Brian" <bkstig***@usa.net> wrote in message
> news:uh0EKjq0FHA.2652@TK2MSFTNGP14.phx.gbl...
> > What is the best way to take to string dates and times...
> >
> > ie.,  10-Oct-2005 10:30:16 AM and 11-Oct-2005 2:17:54 PM
> >
> > and then determine the number of seconds between these two dates?
> >
> > I must be missing a simple function to do the conversion...  but I sure
> > can't seem to find it...
> >
> > Thanks for the help.
> >
> > B
> >
> >
>
>
Author
16 Oct 2005 11:48 PM
MikeD
"Brian" <bkstig***@usa.net> wrote in message
news:uh0EKjq0FHA.2652@TK2MSFTNGP14.phx.gbl...
> What is the best way to take to string dates and times...
>
> ie.,  10-Oct-2005 10:30:16 AM and 11-Oct-2005 2:17:54 PM
>
> and then determine the number of seconds between these two dates?
>
> I must be missing a simple function to do the conversion...  but I sure
> can't seem to find it...


As Someone said (and I still implore him [her?] to come up with some kind of
better alias), DateDiff is what you're looking for. However, anytime you're
dealing with dates and times in string format, you can run into other
problems. Therefore, I suggest that you always convert the date/time strings
to a Date data type first. If there's a problem with the string, you'll find
out about it right then and can take corrective action BEFORE you attempt
anything else that may result in erroneous results.

--
Mike
Microsoft MVP Visual Basic