473,396 Members | 1,799 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.

Convert Date

I am trying to find a way to convert a string date from the format
01/05/2006 to 01/05/06 or 010506.

How would I do that in C#?

Thanks,

Tom
Mar 1 '06 #1
5 6012
DateTime dt = DateTime.Parse("01/05/2006");

string s = dt.ToString("MMddyy");

Console.WriteLine(s);

s = dt.ToString("MM/dd/yy");

Console.WriteLine(s);
--
William Stacey [MVP]

"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
|I am trying to find a way to convert a string date from the format
| 01/05/2006 to 01/05/06 or 010506.
|
| How would I do that in C#?
|
| Thanks,
|
| Tom
|
|
Mar 1 '06 #2
Is there a way to do this in one line?

Thanks,

Tom
"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:ua**************@TK2MSFTNGP09.phx.gbl...
DateTime dt = DateTime.Parse("01/05/2006");

string s = dt.ToString("MMddyy");

Console.WriteLine(s);

s = dt.ToString("MM/dd/yy");

Console.WriteLine(s);
--
William Stacey [MVP]

"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
|I am trying to find a way to convert a string date from the format
| 01/05/2006 to 01/05/06 or 010506.
|
| How would I do that in C#?
|
| Thanks,
|
| Tom
|
|

Mar 1 '06 #3
tshad <ts**********@ftsolutions.com> wrote:
Is there a way to do this in one line?


Well, you can use:

string s = DateTime.Parse(myDateString).ToString("MMddyy");

but do you really think that's clearer than splitting things into two
shorter lines?

What problem are you trying to avoid by doing as much as possible on
one line? Strictly speaking, you can do *almost* anything in a C#
program in one line (preprocessor directives and single line comments
are the exceptions, IIRC) but that doesn't mean it's a good idea.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 1 '06 #4
DateTime dt = DateTime.Parse("01/05/2006").ToString("MMddyy");

--
William Stacey [MVP]
Mar 1 '06 #5
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
tshad <ts**********@ftsolutions.com> wrote:
Is there a way to do this in one line?
Well, you can use:

string s = DateTime.Parse(myDateString).ToString("MMddyy");

but do you really think that's clearer than splitting things into two
shorter lines?


I am trying to look at putting it in my DataGrid in my
TemplateColumn/asp:label statement.

Tom
What problem are you trying to avoid by doing as much as possible on
one line? Strictly speaking, you can do *almost* anything in a C#
program in one line (preprocessor directives and single line comments
are the exceptions, IIRC) but that doesn't mean it's a good idea.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Mar 1 '06 #6

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

Similar topics

1
by: Loi Tan Vo | last post by:
Hi, I have a text file that contains a date column. The text file will be imported to database in SQL 2000 server. After to be imported, I want to convert the date column to date type. For...
19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
1
by: Matt | last post by:
I would like to convert a couple informix stored procedures to SQL Server stored procedures. I have no idea how to accomplish this. Here is an example of one of the procedures I need to convert. ...
3
by: jerry.ranch | last post by:
I have a need to convert simple dates (i.e. 02/14/2005) to a number, do some math, and convert back to a date. (in a simple query). The math involves adding or substracting days, and days of the...
2
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
17
by: Terry Jolly | last post by:
New to C# ---- How do I convert a Date to int? In VB6: Dim lDate as long lDate = CLng(Date) In C#
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
8
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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
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
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.