473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cast string to DateTime

I have an object string property that is a string. I want to convert to a
DateTime. Any ideas?

DateTime eventDt = ((DateTime)mEvent.EventDt).Date;

Error 1 Cannot convert type 'string' to 'System.DateTime'
May 25 '06 #1
3 22308
DateTime eventDt = DateTime.Parse(mEvent.EventDt).Date;

Marc
May 25 '06 #2
"mgonzales3" <mg********@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
I have an object string property that is a string. I want to convert to a
DateTime. Any ideas?

DateTime eventDt = ((DateTime)mEvent.EventDt).Date;

Error 1 Cannot convert type 'string' to 'System.DateTime'


You need to use the Parse or ParseExact methods of the DateTime object.

string strTest = "25 May 2006";
DateTime dtmTest = DateTime.Parse(strTest);

May 25 '06 #3
mgonzales3 <mg********@discussions.microsoft.com> wrote:
I have an object string property that is a string. I want to convert to a
DateTime. Any ideas?

DateTime eventDt = ((DateTime)mEvent.EventDt).Date;

Error 1 Cannot convert type 'string' to 'System.DateTime'


DateTime.Parse()

-- Barry

--
http://barrkel.blogspot.com/
May 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
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,...
0
by: Aaron W. West | last post by:
Fun with CAST! (Optimized SQLServerCentral script posts) I found some interesting "tricks" to convert binary to hexadecimal and back, which allow doing 4 or 8 at a time. Test code first: --...
8
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
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
1
by: Mark Hollander | last post by:
Hi, I am using the WMI management object to obtain values about the network cards installed on the system. The MSDN tells me the following class Win32_NetworkAdapterConfiguration :...
22
by: Simon Says | last post by:
Dear all, I have the following: dim tmpString as String = "11/21/2004 07:55:33" dim tmpDate as Date = CDate(tmpString) But I keep getting <cast from string "11/21/2004 07:55:33" to type...
10
by: Kiran | last post by:
Hi, I am trying to convert a string(Thu Jul 21 00:00:00 UTC+0100 200) to date. I get the following error Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is not...
2
by: elena | last post by:
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...
4
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.