Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date Issue

Author  Topic 

muzammal_janjua
Starting Member

1 Post

Posted - 2010-01-21 : 23:39:07
Hello everyone

its my first post in this group, so i hope a good cooperative response from you guys.

I am having a problem in my MS sql server Database, to support my question i have attached a image , which itself explains the issue.

the dark highlighted area shows a date like 3/8/2009 and light color highlighted area show dates like 2/13/2009 etc

format looks like mm/dd/yyyy

But when i get this date in my VB program, the format changes it like it makes 3/8/2009 as 3 August 2009
and it makes 2/13/2009 as 13 Feb 2009

means the dates in which middle value is less then 10, it convert that into month, otherwise into day.

Why??

i m using this in CODE to convert into my specific format

Global Const gSFormat As String = "DD/MM/YYYY"

mtxtdate = format(sqlDate,gSFormat)


Kindly help..

Thanks

Kristen
Test

22859 Posts

Posted - 2010-01-22 : 01:54:37
The image you have linked to is on your C: drive, so I'm afraid we can't see it. You'll have to upload it somewhere on the internet that you can point to.

SQL stored DATETIME in an internal format that preserves it and allows it to be treated chronologically - e.g. using date functions to add days / months etc., or compare dates.

If you retrieve a DATETIME column from SQL into a Datetime variable in VB I would expect VB to do the same.

You should then apply formatting at the final point, when you display it to the user.

If you are retrieving dates from SQL in string/varchar format then you will be at the mercy of the date conversions involved, which may use the Locale setting on the machine (i.e USA, Europe and Japan settings will cause different results), and your VB may make a different conversion to your SQL conversion.

If you want to present a date to SQL in string format always use yyyymmdd format as SQL will treat this unambiguously (note that to be treated as unambiguous there must be NO hyphens in this format)
Go to Top of Page

Aiby
Yak Posting Veteran

71 Posts

Posted - 2010-01-24 : 10:16:05
I think this should ask in any VB forum! Not an MS SQL related issue. Any way…
One easy way to resolve this issue from VB while dealing with MS SQL server or any database with date type field, input the data (date type) to the database in a format "dd/mmm/yy" format! Eg:- '8-Aug-09' or '08/Aug/09' Only thing you must ensure it is a valid date!



quote:
Originally posted by muzammal_janjua

Hello everyone

its my first post in this group, so i hope a good cooperative response from you guys.

I am having a problem in my MS sql server Database, to support my question i have attached a image , which itself explains the issue.

the dark highlighted area shows a date like 3/8/2009 and light color highlighted area show dates like 2/13/2009 etc

format looks like mm/dd/yyyy

But when i get this date in my VB program, the format changes it like it makes 3/8/2009 as 3 August 2009
and it makes 2/13/2009 as 13 Feb 2009

means the dates in which middle value is less then 10, it convert that into month, otherwise into day.

Why??

i m using this in CODE to convert into my specific format

Global Const gSFormat As String = "DD/MM/YYYY"

mtxtdate = format(sqlDate,gSFormat)


Kindly help..

Thanks

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-24 : 10:22:04
quote:
Originally posted by Aiby

I think this should ask in any VB forum! Not an MS SQL related issue. Any way…
One easy way to resolve this issue from VB while dealing with MS SQL server or any database with date type field, input the data (date type) to the database in a format "dd/mmm/yy" format! Eg:- '8-Aug-09' or '08/Aug/09' Only thing you must ensure it is a valid date!



quote:
Originally posted by muzammal_janjua

Hello everyone

its my first post in this group, so i hope a good cooperative response from you guys.

I am having a problem in my MS sql server Database, to support my question i have attached a image , which itself explains the issue.

the dark highlighted area shows a date like 3/8/2009 and light color highlighted area show dates like 2/13/2009 etc

format looks like mm/dd/yyyy

But when i get this date in my VB program, the format changes it like it makes 3/8/2009 as 3 August 2009
and it makes 2/13/2009 as 13 Feb 2009

means the dates in which middle value is less then 10, it convert that into month, otherwise into day.

Why??

i m using this in CODE to convert into my specific format

Global Const gSFormat As String = "DD/MM/YYYY"

mtxtdate = format(sqlDate,gSFormat)


Kindly help..

Thanks




try to always pass dates in iso format (yyyy-mm-dd)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-24 : 13:08:56
Beware that 'yyyy-mm-dd' will not implicitly cast in all locales. Needs to have no hyphens - i.e. yyyymmdd - to be certain to cast implicitly.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-25 : 03:16:24
<<
try to always pass dates in iso format (yyyy-mm-dd)
>>

You can use that format as long as you use time portion too

yyyy-mm-ddTHH:MM:SS


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -