|
-
Feb 3rd, 2011, 02:25 AM
#1
Thread Starter
Hyperactive Member
get month and year and day in query
i have following query
SELECT DISTINCT DATEADD(day, 0, DATEDIFF(day, 0, starttime)) as date FROM table
and these me return like this
2011-02-03 00:00:00.000
i want to convert that query that give reult like this
thursday ,feburay 2,2011
how to do this ??
-
Feb 3rd, 2011, 04:39 AM
#2
Re: get month and year and day in query
Assuming you have your date in @date variable (otherwise replace with your date column name):
sql Code:
SELECT DATENAME(weekday, @date) + ', ' + DATENAME(month, @date) + ' ' + DATENAME(day, @date) + ', ' + DATENAME(year, @date) + ' '
-
Feb 3rd, 2011, 04:43 AM
#3
Re: get month and year and day in query
Note that we did that because none of the CONVERT options satisfy your need. If you can be content with one of these predefined formats, then you should prefer CONVERT.
http://msdn.microsoft.com/en-us/library/ms187928.aspx
-
Feb 3rd, 2011, 07:53 AM
#4
Thread Starter
Hyperactive Member
Re: get month and year and day in query
it should be like thi s??
DECLARE @VariableName datetime
set @VariableName = SELECT DISTINCT DATEADD(day, 0, DATEDIFF(day, 0, starttime)) as date FROM table
this giving me error ..
Incorrect syntax near the keyword 'SELECT'.
-
Feb 3rd, 2011, 08:15 AM
#5
Re: get month and year and day in query
sql Code:
DECLARE @date DATETIME SELECT DISTINCT @date = DATEADD(day, 0, DATEDIFF(day, 0, starttime)) FROM table1 SELECT DATENAME(weekday, @date) + ', ' + DATENAME(month, @date) + ' ' + DATENAME(day, @date) + ', ' + DATENAME(year, @date) + ' '
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|