Solved

get distinct Dates from timestamp values

Posted on 2013-10-23
4
317 Views
Last Modified: 2013-10-25
hi guys
I have  a MODIFY_DATE timestamp column with values like this
MODIFY_DATE
2013-10-18 10:54:02.270
2013-10-18 10:54:02.270
2013-10-22 06:30:35.373
2013-10-23 16:51:14.790
2013-10-23 16:51:14.790


I am trying to get the Distinct Date from the column, my resultset should look like this
2013-10-18
2013-10-22
2013-10-23

what i have is
select distinct cast(MODIFY_DATE AS Date) as Date from CUSTOMER_TABLE
 where  cast(MODIFY_DATE AS Date) = DATEADD(day, 0, convert(date, GETDATE()))
but this will get only todays date.

Any idea how i can acchieve this?

thanks
0
Comment
Question by:royjayd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 300 total points
ID: 39595618
Worked for me without the WHERE clause..
CREATE TABLE #foo (MODIFY_DATE datetime) 

INSERT INTO #foo (MODIFY_DATE)
VALUES
	('2013-10-18 10:54:02.270'), 
	('2013-10-18 10:54:02.270'), 
	('2013-10-22 06:30:35.373'), 
	('2013-10-23 16:51:14.790'), 
	('2013-10-23 16:51:14.790')

select distinct cast(MODIFY_DATE AS Date) as Date 
from #foo

Open in new window

0
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 300 total points
ID: 39595621
>where  cast(MODIFY_DATE AS Date) = DATEADD(day, 0, convert(date, GETDATE()))
What were you trying to accomplish with the above statement?
DateAdd(day, 0, any date) will equal any date.
0
 
LVL 49

Assisted Solution

by:PortletPaul
PortletPaul earned 100 total points
ID: 39596196
no points please:

yep, all you need to do is remove the where clause

>> where  cast(MODIFY_DATE AS Date) = DATEADD(day, 0, convert(date, GETDATE()))
>> but this will get only todays date.
because that's what you just asked for :)

cast(MODIFY_DATE AS Date)  also could be: convert(date,Modify_date)
convert(date, GETDATE()) also could be: cast(getdate() AS Date)

so, your where clause could be rewritten as:

where cast(MODIFY_DATE AS Date)  = cast(getdate() AS Date)

i.e. only where that field = today
0
 

Author Comment

by:royjayd
ID: 39597940
thanks y'all
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question