473,385 Members | 1,855 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,385 software developers and data experts.

A beginner question about date format

Supose I have a control Text1 with todays date (21/12/2004).
How can I show it in a "yyyymmdd" format?
Solution like Text1.Value.Year.tostring() + .....Month.tostring() + .... Day.tostring() seems to be unelegant..
Nov 16 '05 #1
4 4268
Hi,

You can use DateTime.ToString:
DateTime.Today.ToString( "yy/mm/dd" , DateTimeFormatInfo.InvariantInfo );

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Geri Reshef" <Ge********@Tapuz.co.il> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Supose I have a control Text1 with todays date (21/12/2004).
How can I show it in a "yyyymmdd" format?
Solution like Text1.Value.Year.tostring() + .....Month.tostring() + ..... Day.tostring() seems to be unelegant..
Nov 16 '05 #2
DateTime.Now.ToString("YYYYMMDD");
please refer to some book, if it give u error!
"Geri Reshef" <Ge********@Tapuz.co.il> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Supose I have a control Text1 with todays date (21/12/2004).
How can I show it in a "yyyymmdd" format?
Solution like Text1.Value.Year.tostring() + .....Month.tostring() + ..... Day.tostring() seems to be unelegant..
Nov 16 '05 #3
Hi Geri,

Here's something you could try:

string txtDate = "21/12/2004";

System.Globalization.CultureInfo culture =
new System.Globalization.CultureInfo("FR-fr");

string newDate = DateTime.Parse(txtDate, culture).ToString("yyyyMMdd");

Console.WriteLine(newDate);

The code above demonstrates my suggestion of parsing your text value into a DateTime and reformatting it how you want. I'm making the assumption that you need to specify CultureInfo based on the way you formatted the date. It doesn't parse (raises an exception) on my machine, which is set to en-US.

Joe
--
http://www.csharp-station.com
"Geri Reshef" <Ge********@Tapuz.co.il> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Supose I have a control Text1 with todays date (21/12/2004).
How can I show it in a "yyyymmdd" format?
Solution like Text1.Value.Year.tostring() + .....Month.tostring() + ..... Day.tostring() seems to be unelegant..
Nov 16 '05 #4

Nov 16 '05 #5

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

Similar topics

0
by: Alf P. Steinbach | last post by:
The seventh part of my attempted Correct C++ tutorial is now available, although for now only in Word format (use free Open Office if no Word), and also, it's not yet been reviewed at all -- ...
1
by: Hought, Todd | last post by:
Hi all, trying to run a query against a table, to pull the date out, and order it. problem is, the date is stored in character (string) format, not as an actual timestamp, so parsing it back into...
10
by: StenKoll | last post by:
Hi! I am fairly new to access and not very familiar with vba programming. I am trying to setting up a database of shareholders in a company. So far I have managed to build tables containing owner...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
2
by: Keith | last post by:
Good Afternoon, New to .Net. I am trying to pass date/time values to a MS Access query depending on what value is selected from a dropdown list box (January, February, etc). I have declared...
2
by: Vittorio | last post by:
Context: Pentium PIII, 128 MB RAM, 5400 RPM HD-10GB (of which 1.8 GB as swap disk) Debian linux testing, Postgresql 7.4.2 from the deb box. Beginner with Postgresql but not with linux At...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: RaulAbHK | last post by:
Dear all, I guess this is a basic question with an easy answer but I am a beginner and I would much apreciate your feedbacks. Let's say I have a library with some functionality to perform some...
22
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.