473,804 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime.ParseE xact(..)

Hello,

I have big problem with method ParseExact from class DateTime.
Here is code sample:

'-----------------------------------------------------------------------------------------------------------------------------------------
Module Module1
Sub Main()
Console.WriteLi ne("Start...")
Try
Dim dt_ok As DateTime = New DateTime(1899, 12, 29, 0, 0, 0)
Dim dt_exception As DateTime = New DateTime(1899, 12, 30,
0, 0, 1)

Dim str_ok As String = dt_ok.ParseExac t(dt_ok,
"yyyy-MM-dd", System.Globaliz ation.CultureIn fo.InvariantCul ture)
Console.WriteLi ne("OK: " + str_ok)

Dim str_exception As String =
dt_exception.Pa rseExact(dt_exc eption, "yyyy-MM-dd",
System.Globaliz ation.CultureIn fo.InvariantCul ture)
Console.WriteLi ne("OK: " + str_exception)

Catch ex As Exception
Console.WriteLi ne(ex.Message)
End Try
Console.WriteLi ne("Press ENTER for exit...")
Console.ReadLin e()
End Sub
End Module
'-----------------------------------------------------------------------------------------------------------------------------------------

For date 1899/12/29(or 31) ParseExact works fine but for date
1899/12/30 i have exception:
String was not recognized as a valid DateTime. (thrown by ParseExact )

I have read about structure DateTime and i know that this time is
special but i don't understand why it dosn't want to work :/

Tkank you for all aswears.

regard
Pawel Modrzejewski

Aug 16 '06 #1
1 4472
Pablo,

The datetime.parsee xact converts a string to a datetime
http://msdn.microsoft.com/library/de...xacttopic2.asp

You try to convert a datetime to a string
For that is the overloaded DateTime.ToStri ng very good.

http://msdn.microsoft.com/library/de...ingTopic21.asp

It is very strange that it works with that other date.

I hope this helps,

Cor

"Pablo" <pa******@gmail .comschreef in bericht
news:11******** *************@7 5g2000cwc.googl egroups.com...
Hello,

I have big problem with method ParseExact from class DateTime.
Here is code sample:

'-----------------------------------------------------------------------------------------------------------------------------------------
Module Module1
Sub Main()
Console.WriteLi ne("Start...")
Try
Dim dt_ok As DateTime = New DateTime(1899, 12, 29, 0, 0, 0)
Dim dt_exception As DateTime = New DateTime(1899, 12, 30,
0, 0, 1)

Dim str_ok As String = dt_ok.ParseExac t(dt_ok,
"yyyy-MM-dd", System.Globaliz ation.CultureIn fo.InvariantCul ture)
Console.WriteLi ne("OK: " + str_ok)

Dim str_exception As String =
dt_exception.Pa rseExact(dt_exc eption, "yyyy-MM-dd",
System.Globaliz ation.CultureIn fo.InvariantCul ture)
Console.WriteLi ne("OK: " + str_exception)

Catch ex As Exception
Console.WriteLi ne(ex.Message)
End Try
Console.WriteLi ne("Press ENTER for exit...")
Console.ReadLin e()
End Sub
End Module
'-----------------------------------------------------------------------------------------------------------------------------------------

For date 1899/12/29(or 31) ParseExact works fine but for date
1899/12/30 i have exception:
String was not recognized as a valid DateTime. (thrown by ParseExact )

I have read about structure DateTime and i know that this time is
special but i don't understand why it dosn't want to work :/

Tkank you for all aswears.

regard
Pawel Modrzejewski

Aug 16 '06 #2

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

Similar topics

15
6990
by: Dan S | last post by:
My application asks the user to enter in a date - in the mm/dd/yyyy format. Is there any quick and easy way to verify the date the user enters is formatted correctly? Right now I'm calling DateTime.Parse() and catching the FormatException but it seems this is a bit inefficient - catching the exception that is. There is some pretty obvious delay while it traces back up the call stack. Is there a better way? Something that returns a bool...
16
10517
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am using C# eg. - String variable "strMyDate" holds the value "1/1/2005 12:00:00 AM" from the database. - I do not care about the time portion, I only want "1/1/2005" for display.
4
18173
by: Hans Merkl | last post by:
Does anybody know of a library that can handle strings pf various formats and conver them to a DateTime value? The strings are coming from a webform and I can't restrict the input (it's not my form). I have been using Convert.ToDateTime but it choked on "12:00 noon". I am looking for a function that can make sense out of anything that looks like a date/time. Outlook is pretty good at it when you enter an appointment with the GUI, but...
2
4841
by: Peter Kirk | last post by:
Hi there I would like some help with parsing date strings to DateTime structures. I can see that DateTime has Parse and ParseExact methods - but I am not sure what is best for me to use, and what parameters I need to supply. I reveive a string from a web-form, which would look something like this: "31-12-1999 14:56:22"; and I need to parse it to a DateTime
38
807
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a FormatString, how can you convert the String back to a DateTime? DateTime.Parse(...) doesn't use the FormatString. Now admitedly, if the format string is just "MM", it can't be done. But if the format string is "yyyyMMdd", or "ddMMMyyyy hhmmsst", it...
26
2693
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM' How do i do that? Reny ---
11
7258
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why only that I have to listen to them because they know it better. They told also that in a business situation it is better to use datetime.parseexact for changing cultures and not to use the globalization setting. I did not give them this sample,...
1
15037
by: Erica | last post by:
Hi. I have a string: "11/24/2006 23:59" named StartDateTime I need the string to be converted into a DateTime object in the following format: 2006-11-24 11:59 PM I tried the following: DateTime.ParseExact(StartDateTime,"yyyy-MM-dd HH:mm tt*", System.Globalization.CultureInfo.CurrentCulture)
11
9844
by: Peter Holschbach | last post by:
Hi, I've the following line of code: result = DateTime.ParseExact("1999-12-01T23:59:59Z", "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture); where I get in result "result" "02.12.1999 00:59:59" instead of teh expected "01.12.1999 23:59:59" Anybody a idea ?
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5530
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
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
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.