Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Starting Member

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

Flowing Fount of Yak Knowledge

2242 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( 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 ' 

Go to Top of Page

Premature Yak Congratulator

22864 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?


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000