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.
Author |
Topic |
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2014-02-12 : 07:37:11
|
HI Guys I need some help Aim - To calculate how many months are between the current date minus the First_Post_DateFor example The First_Post_Date is displayed as follows following “25/07/2012”Current date is 12-02-2014The difference between the two dates is approx 20months To make the calculation easier, it might be easier to default the day of First_Post_Date to 01and do the same with the currentdateSo it would be 01/07/12 and 01/02/14Looking forward to your help |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-12 : 07:38:31
|
DATEDIFF(mm,First_Post_Date,GETDATE())------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2014-02-12 : 07:42:10
|
hi Visakh16 I get the following error msg Msg 241, Level 16, State 1, Line 2Conversion failed when converting date and/or time from character string. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-12 : 08:35:29
|
quote: Originally posted by masond hi Visakh16 I get the following error msg Msg 241, Level 16, State 1, Line 2Conversion failed when converting date and/or time from character string.
whats the data type of First_Post_Date?anyways try this tooDATEDIFF(mm,CONVERT(datetime,First_Post_Date,103),GETDATE()) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|
|
|