468,544 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

problem with date format

Sam
Hi,
I store the date selected in a datetimepicker into a sqlserver table in
a SmallDateTime field.
To be compatible with the date format of my sql server, I convert the
date as following:

Dim d As Date
Dim dInDate As Date

Dim ciOriginal As cultureinfo
Dim ciDatabase As cultureinfo

ciOriginal = Thread.CurrentThread.CurrentCulture
ciDatabase = CultureInfo.CreateSpecificCulture("en-US")

Thread.CurrentThread.CurrentCulture = ciDatabase

dInDate = Date.Parse(Data("ExpiryDate").ToString)

d = Date.Parse(Data("ExpiryDate").ToString)

It works fine. Issue is : how to get the sqlserver date format as I
don't want to hardcode en-US as I do above.

Thanks!

Dec 13 '05 #1
3 1789

Sam wrote:
Hi,
I store the date selected in a datetimepicker into a sqlserver table in
a SmallDateTime field.
To be compatible with the date format of my sql server, I convert the
date as following:

Dim d As Date
Dim dInDate As Date

Dim ciOriginal As cultureinfo
Dim ciDatabase As cultureinfo

ciOriginal = Thread.CurrentThread.CurrentCulture
ciDatabase = CultureInfo.CreateSpecificCulture("en-US")

Thread.CurrentThread.CurrentCulture = ciDatabase

dInDate = Date.Parse(Data("ExpiryDate").ToString)


Hang on. Data("ExpiryDate") comes from SQL, and it's a date, so why
convert it to a string (creating culture issues)? A SqlDateTime can be
directly converted to a Date - this avoids all culture issues.

--
Larry Lard
Replies to group please

Dec 13 '05 #2
Sam,

Both the DateTime and the SmallDateTime are culture independend.

From MSDN about SmallDateTime
The first 2 bytes store the number of days after January 1, 1900. The other
2 bytes store the number of minutes since midnight. Dates range from January
1, 1900, through June 6, 2079, with accuracy to the minute.

Therefore the value from your datetimepicker is already in the right
datetime format.

ciDatabase = datetimepicker.value should be enough.

I hope this helps,

Cor

"Sam" <re************@hotmail.co.uk> schreef in bericht
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,
I store the date selected in a datetimepicker into a sqlserver table in
a SmallDateTime field.
To be compatible with the date format of my sql server, I convert the
date as following:

Dim d As Date
Dim dInDate As Date

Dim ciOriginal As cultureinfo
Dim ciDatabase As cultureinfo

ciOriginal = Thread.CurrentThread.CurrentCulture
ciDatabase = CultureInfo.CreateSpecificCulture("en-US")

Thread.CurrentThread.CurrentCulture = ciDatabase

dInDate = Date.Parse(Data("ExpiryDate").ToString)

d = Date.Parse(Data("ExpiryDate").ToString)

It works fine. Issue is : how to get the sqlserver date format as I
don't want to hardcode en-US as I do above.

Thanks!

Dec 13 '05 #3
Sam
Hi guys,
Thanks a lot for your replies.
In fact, I had trouble with that because I was doing
datetimepicker.Text instead of datetimepicker.value as Cor suggested.

It works now. ;-)
Thank you.

Dec 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Geoff Jones | last post: by
12 posts views Thread by Assimalyst | last post: by
3 posts views Thread by Steven Smith | last post: by
1 post views Thread by swathichavalla | last post: by
11 posts views Thread by jessy | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.