SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 get time difference
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

younas02
Starting Member

Pakistan
28 Posts

Posted - 11/27/2012 :  02:39:38  Show Profile  Reply with Quote
i have a date field with type varchar. now i want to get time difference in days with today's date how can i get it?
actually i want to get rows which have day difference of more than 30 days.I have a field of lastlogin,i want to compare lastlogin with today's datetime and if the difference is more than 30 days we want to send those persons emails.

Edited by - younas02 on 11/27/2012 02:51:28

bandi
Flowing Fount of Yak Knowledge

India
2215 Posts

Posted - 11/27/2012 :  03:40:04  Show Profile  Reply with Quote
see this code once

DECLARE @fromDate datetime2 ='2012-10-27 13:05:00'

SELECT DATEDIFF(DD, @fromDate, GETDATE()) DaysDiff

SELECT DATEDIFF( hh, @fromDate, GETDATE()) HoursDiff, DATEDIFF( MI, @fromDate, GETDATE()) MinutesDiff, DATEDIFF( hh, @fromDate, GETDATE())/24 DaysDiff

SELECT convert(varchar(5),datediff(HOUR ,@fromdate,GETDATE())) + ' hour '+
convert(Varchar(5),DATEDIFF (Minute,@fromDate,GETDATE())%60) +' Minute ' + 
convert(Varchar(5),DATEDIFF (SECOND ,@fromDate,GETDATE())%60) +' Second ' 


--
Chandu
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 11/29/2012 :  06:33:27  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Why did you use varchar datatype to store dates? What is the format of varchar dates?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000