By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Determining whether a string is a date, time, or date and time

P: n/a
When determining whether a String can be converted to a DateTime, you can
use the IsDate() method. However, I would also like to know whether the
string is a date, a time, or both a date and a time. Is there any simple way
to do this without using manual pattern matching? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Mar 26 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Nathan Sokalski" <nj********@hotmail.comwrote in
news:O8**************@TK2MSFTNGP04.phx.gbl:
When determining whether a String can be converted to a DateTime, you
can use the IsDate() method. However, I would also like to know
whether the string is a date, a time, or both a date and a time. Is
there any simple way to do this without using manual pattern matching?
Thanks.
Perhaps you can use the Convert.ToDate() function? Once you convert it to a
date, you can check the .Date and .Time properties to determine the
original values?

--
sp**********@rogers.com (Do not e-mail)
Mar 27 '08 #2

P: n/a
This would not work. The reason I need to know this information is so that I
know whether to include the date, time, or both when submitting the data to
a database. The reason your suggestion will not work is because a Date
object ALWAYS has a date and time, even if the date is the default date or
the time is 0:00 or 12:00 or whatever. Therefore, looking at these parts of
the Date will tell me nothing about whether a date, time, or both were
included in the original String.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Nathan Sokalski" <nj********@hotmail.comwrote in
news:O8**************@TK2MSFTNGP04.phx.gbl:
>When determining whether a String can be converted to a DateTime, you
can use the IsDate() method. However, I would also like to know
whether the string is a date, a time, or both a date and a time. Is
there any simple way to do this without using manual pattern matching?
Thanks.

Perhaps you can use the Convert.ToDate() function? Once you convert it to
a
date, you can check the .Date and .Time properties to determine the
original values?

--
sp**********@rogers.com (Do not e-mail)

Mar 27 '08 #3

P: n/a
Nathan,

Just creating a different box for the date and time string makes things a
lot easier.
Especially on a website where this is even more common.

There are in different cultures two kind of clock registrations used.

With an 24 hour clock and a 12 hour clock even about this you have to take
care of.

Cor

Mar 27 '08 #4

P: n/a
Which DB are you using ? It also has a default time anyway so even if you
don't include a time part it will have a default time part server side ?

"Nathan Sokalski" <nj********@hotmail.coma écrit dans le message de news:
%2****************@TK2MSFTNGP03.phx.gbl...
This would not work. The reason I need to know this information is so that
I know whether to include the date, time, or both when submitting the data
to a database. The reason your suggestion will not work is because a Date
object ALWAYS has a date and time, even if the date is the default date or
the time is 0:00 or 12:00 or whatever. Therefore, looking at these parts
of the Date will tell me nothing about whether a date, time, or both were
included in the original String.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
>"Nathan Sokalski" <nj********@hotmail.comwrote in
news:O8**************@TK2MSFTNGP04.phx.gbl:
>>When determining whether a String can be converted to a DateTime, you
can use the IsDate() method. However, I would also like to know
whether the string is a date, a time, or both a date and a time. Is
there any simple way to do this without using manual pattern matching?
Thanks.

Perhaps you can use the Convert.ToDate() function? Once you convert it to
a
date, you can check the .Date and .Time properties to determine the
original values?

--
sp**********@rogers.com (Do not e-mail)


Mar 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.