Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2005, 07:32 AM
Registered User
 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Convert string to datetime

Help!!!
In my windows form application convert from string e.g. "04/30/2005 11:59:00" to datetime work fine but in my windows service convert from string to datetime always convert early string to format "30.4.2005 11:59:00" .


 
Old April 4th, 2005, 01:41 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think you should change the culture of your CurrentThread,try
Code:
Thread.CurrentThread.CurrentCulture=new CultureInfo("en-US");
does this work?

_____________
Mehdi.
software student.
 
Old April 4th, 2005, 02:25 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

or try this,
Code:
CultureInfo cf=new CultureInfo("en-US");
//yourString is according to en-US format
//if not you will recieve FormatException
DateTime dt=DateTime.Parse(yourString,cf);
//then you can convert every DateTime to string
//according to the culture
string sdt=dt.ToSting(cf);
HtH.

_____________
Mehdi.
software student.
 
Old April 5th, 2005, 06:47 AM
Registered User
 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I change culture and I have error:

ERROR OCCOURED IN:Microsoft.VisualBasic
ERROR DESCRIPTION:Cast from string "03.28.2005 00:00:00" to type 'Date' is not valid.
ERROR DESCRIPTION: at Microsoft.VisualBasic.CompilerServices.DateType.Fr omString(String Value, CultureInfo culture)
   at Microsoft.VisualBasic.CompilerServices.DateType.Fr omString(String Value)

 
Old April 5th, 2005, 11:57 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

did you have a look at my previous post?

I saw this "03.28.2005 00:00:00" a strange format,you can replace . with / and parse the new string.

_____________
Mehdi.
software student.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert String to DateTime SimoNWellborne C# 3 October 11th, 2014 02:24 AM
convert string to datetime in VB.net lisabb ASP.NET 2.0 Basics 3 June 19th, 2007 06:52 AM
How to convert a string in DateTime elena SQL Language 6 March 29th, 2006 06:59 PM
Convert DateTime rgerald SQL Server 2000 3 October 5th, 2004 09:00 PM
How to convert a string in DateTime elena ADO.NET 3 July 24th, 2003 04:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.