473,549 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,0 9,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 13258
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.co m

"elena" <el***@discussi ons.microsoft.c omwrote in message
news:15******** *************** ***********@mic rosoft.com...
Hi, All
Please, i need help with cast string to DateTime:

DateTime dt = new DateTime(2006,0 9,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.DBTim e).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.co m

"elena" <el***@discussi ons.microsoft.c omwrote in message
news:15******** *************** ***********@mic rosoft.com...
Hi, All
Please, i need help with cast string to DateTime:

DateTime dt = new DateTime(2006,0 9,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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3795
by: jguilford | last post by:
I have created a SQL Stored Procedure that uses a Case statement to determine the Order By. For one of the Case statements I am trying to turn a Char field into Datetime in for the Order By, however I can not get it to work. Can someone please take a look and my code below and tell me what I am doing wrong. Thank you. ORDER BY CASE WHEN...
8
1659
by: CA | last post by:
Hi, I have a function where I would like to test whether an object is of a certain type. Here is my code so far. public bool HasValidType(Type t, object val) { try { if (t==typeof(double))
1
5069
by: Kevin | last post by:
Hi All I am having a problem retrieving a Date value from an Access 2000 database using the OLEDbProvider. Can someone tell me please how to create a DateTime Object with the date fro m the Database, I need the database date to subtract it from another date I have to gain the number of days that have elapsed. I just cannot seem to get this...
7
12013
by: simon | last post by:
I declare variable as int16: int16 hourS; then I open dataReader and set the variable: hourS=rdr.getInt16(1); but I get an error when I start the page:
15
9051
by: JenHu | last post by:
Hi expert, I have a data field (birthdate) contains a datetime datatype (mm/dd/yyyy), how can I convert to mmdd?? say, the birthday is 8/1/1979 and convert to mmdd DOB = DS.Tables("AcctInfoTble").Rows(3)("BRTHDATE") strResult.Insert(12, DOB.PadLeft(37, " ")) ...
2
2122
by: zafzal | last post by:
Hello all, I have a textbox in my asp.net (vb.net) aplicattion, I need to assign it's value to a Variable of type DATE, but it's not a required field, so sometimes I want to send a blank field. I declared a variable as a date datatype and when it´s going to receive the content of the text field, it shows the following error "Cast from
1
9376
by: Mike the Canadian | last post by:
Suppose I have a MySQL 5 table with a DateTime field in it. The table has two records where the time is blank. Running: SELECT CAST(DateTimeField AS TIME) FROM MyTable shows two records with NULL as the resultset. Running: SELECT * FROM MyTable WHERE CAST(DateTimeField AS TIME)=NULL
5
2309
by: AMP | last post by:
Hello, I want to add some variables to a string and this isnt working. textBox1.Text="'BSL version='+ bslVerHi+ bslVerLo"; What am I doing wrong? Thanks Mike
4
2811
by: Terry | last post by:
I have a TextBox with a date such as 15/01/2006 which I want to cast into a variable as a short date 15/01/06, also I need to cast a time such as 07:30 A.M. into a variable as a short time. What is the best syntax for this please? Regards
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7491
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3509
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.