Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - date time formatting

Reply
 
Old 07-07-2008   #1 (permalink)
Andrew


 
 

date time formatting

hi,

my sp takes datetime in 'yyyyMMdd HH:mm:ss' format.

however my c# datetimepicker takes 'dd/MM/yy HH:mm:ss' format.

how do i convert/parse the datetime value from the datetimepicker to the sp
datetime format ? I've tried:
eg.
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime dt3 = DateTime.ParseExact("20080722 10:00:00" , "yyyyMMdd
HH:mm:ss", culture);

No matter what datetime format I pass in, I will always get a "dd/MM/yyyy
HH:mm:ss" format in return, which is not what I want to get. Is my culture
wrong ?

Any advice is appreciated.
Thanks in advance.

regards,
Andrew



My System SpecsSystem Spec
Old 07-07-2008   #2 (permalink)
Jan Hyde (VB MVP)


 
 

Re: date time formatting

Andrew <Andrew@xxxxxx>'s wild thoughts
were released on Mon, 7 Jul 2008 01:51:01 -0700 bearing the
following fruit:
Quote:

>hi,
>
>my sp takes datetime in 'yyyyMMdd HH:mm:ss' format.
>
>however my c# datetimepicker takes 'dd/MM/yy HH:mm:ss' format.
>
>how do i convert/parse the datetime value from the datetimepicker to the sp
>datetime format ? I've tried:
>eg.
>IFormatProvider culture = new CultureInfo("en-US", true);
>DateTime dt3 = DateTime.ParseExact("20080722 10:00:00" , "yyyyMMdd
>HH:mm:ss", culture);
>
>No matter what datetime format I pass in, I will always get a "dd/MM/yyyy
>HH:mm:ss" format in return, which is not what I want to get. Is my culture
>wrong ?
>
Store your date in the format you want in a string and pass
that to your sp.
--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
My System SpecsSystem Spec
Old 07-08-2008   #3 (permalink)
Mihai N.


 
 

Re: date time formatting

Quote:

> my sp takes datetime in 'yyyyMMdd HH:mm:ss' format.
>
> however my c# datetimepicker takes 'dd/MM/yy HH:mm:ss' format.
DateTimePicker.Value Property is a DateTime, no need to go thru a
string and then parse it.


--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
My System SpecsSystem Spec
Old 07-08-2008   #4 (permalink)
Andrew


 
 

Re: date time formatting

Hi thanks for your reply.

The sp takes datetime in format 'yyyyMMdd HH:mm:ss'
The datetime picket produces a value in format 'dd/MM/yyyy HH:mm:ss'
I just modified the sp to take in a varchar(17) and cast it to a datetime
format.

cheers
Andrew

"Mihai N." wrote:
Quote:

>
Quote:

> > my sp takes datetime in 'yyyyMMdd HH:mm:ss' format.
> >
> > however my c# datetimepicker takes 'dd/MM/yy HH:mm:ss' format.
>
> DateTimePicker.Value Property is a DateTime, no need to go thru a
> string and then parse it.
>
>
> --
> Mihai Nita [Microsoft MVP, Visual C++]
> http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email
>
My System SpecsSystem Spec
Old 07-09-2008   #5 (permalink)
Mihai N.


 
 

Re: date time formatting

> The datetime picket produces a value in format 'dd/MM/yyyy HH:mm:ss'
Make sure that the result is 'dd/MM/yyyy HH:mm:ss' even for non-US
systems, otherwise you might have a nasty surprise later on.


--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Date and Time run amok .NET General
date formatting PowerShell
Problem formatting date PowerShell
Date and Time Vista General
Date and Time Tutorials


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46