Cast string to DateTime type for Access Short Time field

G

Guest

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

Guest

Thank you, it works:
string td = "13:30";
cmd.Parameters.Add("@IsTime", OleDbType.DBTime).Value = @TimeSpan.Parse(td);


Nicholas Paldino said:
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]
- (e-mail address removed)

elena said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top