Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-06-2009
Member
 
Join Date: Mar 2009
Posts: 30
datediff query mssql select

I am working in a company & require a application which has all the information of office staff. I am doing this in SQL Server I want to calculate the date difference of the current date & date of joining in the format dd/mm/yyyy. Can anyone provide with the code here....??? Please Help..!
Reply With Quote
  #2  
Old 09-06-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: datediff query mssql select

Example :

Code:
DECLARE    @Dates TABLE (StartingDate DATETIME, EndingDate DATETIME)

INSERT     @Dates
SELECT     '20091005', '20091230' UNION ALL
SELECT     '20091005', '20091230' UNION ALL
SELECT     '20091005', '20091230' 

-- Show the expected output

SELECT     StartingDate,
           EndingDate,
           DATEDIFF(MONTH, StartingDate, EndingDate) AS [Month DatePart],
           DATEDIFF(YEAR, StartingDate, EndingDate) AS [Year DatePart]
FROM       @Dates
ORDER BY   StartingDate
Code:
Starting date            Ending date                Diff in Months  Diff in Years
-----------------------  -----------------------    --------------  -------------
2009-10-05 00:00:00.000  2009-12-30 00:00:00.000    02              0
2009-10-05 00:00:00.000  2009-12-30 00:00:00.000    02              0
2009-10-05 00:00:00.000  2009-12-30 00:00:00.000    02              0
Reply With Quote
  #3  
Old 09-06-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: datediff query mssql select

Here is the similar kind of query asked before Look At the link Below Hope it Helps You....!

How do I use DATEDIFF to count only working days?
Reply With Quote
  #4  
Old 09-06-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: datediff query mssql select

Try this :

Code:
select datediff(d,getdate(),'1/7/2008')
Hope it helps
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "datediff query mssql select"
Thread Thread Starter Forum Replies Last Post
select dropdown with two Sql query aspkiddy Software Development 2 26-06-2011 11:44 PM
VBScript DateDiff Function Zool Software Development 5 15-12-2009 12:05 PM
MySQL query select all columns but exclude specific. RSeven Software Development 3 29-07-2009 09:26 PM
Turn on MySQL query cache to speed up query performance DMA2Superman Software Development 3 07-07-2009 10:26 AM
How do I use DATEDIFF to count only working days? HAYES Microsoft Project 2 24-06-2008 04:46 PM


All times are GMT +5.5. The time now is 01:25 AM.