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
 Date Format

Author  Topic 

Steve2106
Posting Yak Master

183 Posts

Posted - 2008-08-21 : 09:05:17
Hi Guys,

Can someone help me with some query code.
The results returned from my query give the dates with the time portion included. I need to get just the date part. How would I do that. My query is this:
Select
tbMatTrack.Description,
tbMatOrg.FirstName + ' ' + tbMatOrg.LastName As ResponsiblePersonFullName,
tbMatTrack.PlannedStartDate,
tbMatTrack.ActualStartDate,
tbMatTrack.PlannedCompletionDate,
tbMatTrack.ActualCompletionDate
From
tbMatTrack Inner Join
tbMatOrg On tbMatTrack.ResponsibleId = tbMatOrg.PersonnelId
Where
tbMatTrack.ActionId = 2

And this is the date result:

2008-05-26 00:00:00.000

I want it to be 2008-05-26

Thanks for your help,

Steve.




Steve

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-21 : 09:08:17
Where do you want to show data?

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-21 : 09:37:17
Either try to do this formatting at your front end application or if you really have to do it in T-SQL, use CONVERT with appropriate format style. Look into books online for various styles available.
Go to Top of Page

Steve2106
Posting Yak Master

183 Posts

Posted - 2008-08-21 : 09:54:12
Hi There,
I am using the query to pull out a record from the database into a dataset.
I am then looping through the fields and building a string to send an email.

I would prefer to do it in the query, if not I am using Asp.Net (VB) how would I do it once I have the dataset in VB?

Thanks for your help.

Best Regards,

Steve.

Steve
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-21 : 10:08:17
Try using Format() function.
Go to Top of Page

sergio211956
Starting Member

1 Post

Posted - 2008-08-21 : 10:12:49
or try:
ToShortDateString()
Go to Top of Page

ma.voice
Starting Member

12 Posts

Posted - 2008-08-22 : 11:46:07
hi,

For TSQL fix ... try these

1.

select convert(varchar(14),getdate(),111)

2.

select convert(varchar(4),datepart(yyyy,getdate()))+'-'+convert(varchar(2),datepart(mm,getdate()))+'-'+convert(varchar(2),datepart(dd,getdate()))

Cheers

Silent Voice
Bill Gates, MVP
Go to Top of Page
   

- Advertisement -