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
 General SQL Server Forums
 New to SQL Server Programming
 datetime to yyymmdd

Author  Topic 

bill_
Starting Member

38 Posts

Posted - 2010-02-16 : 18:47:30
Am trying convert(char(8),datecol,112) in a query to try to go from datecols datetime type to yyyymmdd.Getting error message that datecol is not a the datasource.

It is in a vb.net program.
Without the convert, the query runs but returns a date and time and just want the date.
Running in the sql server management studio, it works too.

How do I get the query to return yyymmdd or mm/dd/yy ?

Thanks.

X002548
Not Just a Number

15586 Posts

Posted - 2010-02-16 : 19:34:59
want to post the query?

my esp usb port is clogged



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-16 : 23:47:14
quote:
Originally posted by bill_

Am trying convert(char(8),datecol,112) in a query to try to go from datecols datetime type to yyyymmdd.Getting error message that datecol is not a the datasource.

It is in a vb.net program.
Without the convert, the query runs but returns a date and time and just want the date.
Running in the sql server management studio, it works too.

How do I get the query to return yyymmdd or mm/dd/yy ?

Thanks.



you can use the below to get only date part

DATEADD(dd,DATEDIFF(dd,0,yourdatefield),0)

then you can use formatting functions available at your front end to get the date in format you want.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

onlyforme
Starting Member

25 Posts

Posted - 2010-02-17 : 01:26:56
check this link

http://www.sqlusa.com/bestpractices/datetimeconversion/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-17 : 01:27:37
quote:
Originally posted by bill_

Am trying convert(char(8),datecol,112) in a query to try to go from datecols datetime type to yyyymmdd.Getting error message that datecol is not a the datasource.

It is in a vb.net program.
Without the convert, the query runs but returns a date and time and just want the date.
Running in the sql server management studio, it works too.

How do I get the query to return yyymmdd or mm/dd/yy ?

Thanks.



Make use of Format function in VB.NET

Madhivanan

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

- Advertisement -