469,898 Members | 2,144 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Cast string to DateTime type for Access Short Time field

Hi, All
Please, i need help with cast string to DateTime:

DateTime dt = new DateTime(2006,09,17); it works i can update Field in
Access DB
Next field is Short Time data type, how i can cast
string myTime = "13:30";

elena
Sep 20 '06 #1
2 13028
elena,

You can't cast, but you can convert.

Use the static Parse method on the TimeSpan class to convert this to a
TimeSpan instance. If you need that time to be for a specific date, then
you need to create a DateTime instance for the date that this time is on,
then add the time to that date and produce a new DateTime instance.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"elena" <el***@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
Hi, All
Please, i need help with cast string to DateTime:

DateTime dt = new DateTime(2006,09,17); it works i can update Field in
Access DB
Next field is Short Time data type, how i can cast
string myTime = "13:30";

elena

Sep 20 '06 #2
Thank you, it works:
string td = "13:30";
cmd.Parameters.Add("@IsTime", OleDbType.DBTime).Value = @TimeSpan.Parse(td);
"Nicholas Paldino [.NET/C# MVP]" wrote:
elena,

You can't cast, but you can convert.

Use the static Parse method on the TimeSpan class to convert this to a
TimeSpan instance. If you need that time to be for a specific date, then
you need to create a DateTime instance for the date that this time is on,
then add the time to that date and produce a new DateTime instance.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"elena" <el***@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
Hi, All
Please, i need help with cast string to DateTime:

DateTime dt = new DateTime(2006,09,17); it works i can update Field in
Access DB
Next field is Short Time data type, how i can cast
string myTime = "13:30";

elena


Sep 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by jguilford | last post: by
1 post views Thread by Kevin | last post: by
7 posts views Thread by simon | last post: by
1 post views Thread by Mike the Canadian | last post: by
5 posts views Thread by AMP | last post: by
4 posts views Thread by Terry | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.