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 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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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.
...
|
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....
|
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...
|
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...
|
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!...
|
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...
|
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
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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: 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...
|
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,...
| |