473,503 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert string 5/15/2008 to date time 15/5/2008 in c#

1 New Member
hello all aim a newbie in c# please tell me

how shall i convert string 5/15/2008 to date time 15/5/2008 in c#
and copmare the same with 14/5/2008
May 7 '08 #1
2 1207
Frinavale
9,735 Recognized Expert Moderator Expert
hello all aim a newbie in c# please tell me

how shall i convert string 5/15/2008 to date time 15/5/2008 in c#
and copmare the same with 14/5/2008
Usually dates are changed around based on the user's Culture.

If your culture is set to en-US then your dates will be displayed:
"mm/dd/yyyy"

Whereas if your culture is set to fr-FR or es-ES then your dates will be displayed:
"dd/mm/yyyy"

By setting your user's culture you can format the way things are displayed...
Expand|Select|Wrap|Line Numbers
  1. Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-US")
  2. Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
Please note that the above code will not only display your dates in the format for en-US, it will also attempt to look for any resources indicated for en-US.

If you want to force your date to always be in one format, despite the user's culture settings, use the DateTimeFormatInfo object...

You should also look into Globalization.


-Frinny
May 7 '08 #2
blackjack2150
79 New Member
You can also do it by hand and avoid any possible Format mismatches:

Use the string Split() method to get the 3 components and then create a new DateTime object using the constructor that asks for 3 integers (date, month, year).

To convert a string to int use Convert.ToInt32() method.

GL.
May 8 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
10859
by: Abhishek Srivastava | last post by:
Hello All, I wrote the following program. using System; using System.Globalization; public class ShortDateTest { public static void Main(string args)
0
1407
by: Randall Parker | last post by:
I realize that methods like DateTime.ToLocalTime() and DateTime.ToUniveralTime() exist. But suppose one wants to query out data from a database that has UTC times in it. Suppose one wants to have...
14
3378
by: eric.goforth | last post by:
Hello, I'm trying to convert a string to a date time in a C# web service. I'm passing in a string parameter and I have a localization setting in my Web.config file: My app is blowing up on...
0
2742
by: Raju5725 | last post by:
Hi... I am having string variable "BEGIN_DATE_TIME", in which there are three other variables each gives me ....month, date in on string and year in one string and time in another strings(Str2 &...
4
82910
by: sang | last post by:
How can I convert a string like '11-oct-2006' into a valid mysql date? the date_format doesnot change the string in requried date format. create table sample(name varchar(20),date varchar(16));...
4
83862
by: Aobaidat79 | last post by:
Dear Freinds I have string contains the date like "21Jun2000" What I want to do is to convert that string into date in the following format 21 Jun 2000 Plesae help me as soon as possible...
3
4336
by: spooky | last post by:
Hi, I want to convert the string Sat Oct 25 00:00:00 GMT+05:30 2008 into yyyy-mm--dd fornat . Can any one show me how. Regards Anil
6
31920
by: dmorand | last post by:
I've got two fields in my database. There are date and time fields, but they are both type text. I need to concatenate these fields together and convert them to a date/time data type. I've tried a...
7
1842
by: brainbox | last post by:
I have 2 questions: 1.When I read the number using (\S+) its getting stored as 2.08E13. Code I used: if ($line=~/4_begindt_(\S+)/) { print "$1\n" } # $1=2.08E13; instead $1 should contain...
5
3407
satiss7pwr
by: satiss7pwr | last post by:
I have a string date like this: "3/28/2008 12:05:45 pm" i want to convert it into date and display the out put any one can help me plssssssssss
0
7093
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...
0
7287
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
7348
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...
0
7467
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
5592
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,...
0
4685
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...
0
3175
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...
0
1519
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 ...
0
397
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...

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.