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

text date conversion

Hi peeps

I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).

I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).

I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.

Help appreciated!

Cheers
Dan
Nov 18 '05 #1
4 1599
DateTime.ToString("yyyy-MM-dd");

"dhnriverside" <da*@musoswire.com> wrote in message
news:F9**********************************@microsof t.com...
Hi peeps

I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).

I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).

I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.

Help appreciated!

Cheers
Dan
Nov 18 '05 #2
Easy,

Split the string "mm/dd/yyyy" into an array using the delimiter "/" so that
you get:

[mm]
[dd]
[yyyy]

Then swap array positions so you get:

[yyyy]
[mm]
[dd]

Then join the array using the "-" character.

Why you would choose to store DATES as STRINGS is beyond me (just sounds
like a really, really newbie solution)...but if it floats your boat, then
there's your solution.

"dhnriverside" wrote:
Hi peeps

I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).

I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).

I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.

Help appreciated!

Cheers
Dan

Nov 18 '05 #3
Hi Charles

Thanks for that. Yeah it was very newbie. The original system was written
with Access/ASP and as I said I had tremendous trouble with pulling dates out
the database.

Sussed that now, but im writing V2, it's just easier to continue with this
system than converting allllll the data :o)

Cheers for the answer!
Dan

"Charles Chen" wrote:
Easy,

Split the string "mm/dd/yyyy" into an array using the delimiter "/" so that
you get:

[mm]
[dd]
[yyyy]

Then swap array positions so you get:

[yyyy]
[mm]
[dd]

Then join the array using the "-" character.

Why you would choose to store DATES as STRINGS is beyond me (just sounds
like a really, really newbie solution)...but if it floats your boat, then
there's your solution.

"dhnriverside" wrote:
Hi peeps

I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).

I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).

I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.

Help appreciated!

Cheers
Dan

Nov 18 '05 #4
Dan,

You could always use the build in formatting on the DateTime object.

string s = "25/12/2004"
DateTime d = DateTime.ParseExact( s, "d/M/yyyy", null );

Now the variable 'd' will hold the date exactly as Dec 25, 2004.

You can get the date back out in any format you want using the .ToString()
method.

Console.WriteLine( d.ToString( "yyyy-MM-dd" ) )

Here are a couple links for DateTime formatting. These are gem pages for
working with any DateTime formatting issues.

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

Happy formatting!

bill

"dhnriverside" <da*@musoswire.com> wrote in message
news:F9**********************************@microsof t.com...
Hi peeps

I have a datepicker control that's providing dates in the format dd/mm/yyyy (UK).

I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).

I used to use ASP, and it was easy, using a combination of Left() Mid() and Right(), but I can't work out how to do this conversion in C#.

Help appreciated!

Cheers
Dan

Nov 18 '05 #5

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

Similar topics

3
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
5
by: deko | last post by:
After importing text date fields, the dates look like this: 12/31/2003 8:00:00 AM I'm having trouble working with these dates with Date(), Now(), etc, -- does not seem to match these dates....
4
by: Sandy Fleming | last post by:
What is the easiest way to force Access to read a date in a specific format? I have an application that imports a delimited text file with a date field in the format "mm/dd/yyyy". I've...
1
by: Riley DeWiley | last post by:
I have an UPDATE query that is always setting 0 records. When I cut and paste the SQL into Access and use it, it fails in the same way unless I coerce the date fields to be '=now()', in which case...
4
by: Annie D via AccessMonster.com | last post by:
Problem! I have a series of CSV files that I am bringing in to Access, contained within each of them are 6 date fields, however, they are not being recognized as dates…this is a big problem!...
8
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
1
by: Beckster6701 | last post by:
I have a MSAccess database that is linked to a SQL server. I cannot change the SQL server datatype as I am not the only one that uses the database. I'm trying to convert the text field to a valid...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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,...

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.