Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello,
my question is "i have some dates in Employee table like as 01/01/2011,01/01/2010,24/02/2010,19/12/2009,07/07/2008,21/12/2009,24/08/2010,03/03/2011,01/04/2011. "



When i run this query "select MAX(DateOf_joining) from Employee " i found this answer "24/08/2010".

also i run this query "select MIN(DateOf_joining) from Employee" i found this answer "01/01/2010".
Posted
Updated 10-Apr-11 21:40pm
v2

Gives you the latest date.
select top 1 DateOf_joining from Employee order by DateOf_joining desc


Gives you the first(initial) date
select top 1 DateOf_joining from Employee order by DateOf_joining asc
 
Share this answer
 
Hi Ramalinga,

I Have try Ur doubt it's working fine the query u have used is right one.

Main thing is first check ur database column datatype whether is Date or Datatime .
I have tried with Date datatype it's working Fine.

Here what i have received as output :


select MIN(DateOf_joining) from Employee =====> Gives me : 2008-07-07

And

select MAX(DateOf_joining) from Employee =====> Gives me :2011-04-01

So just Check ur datatype field of DateOf_joining column in ur Employee table.

Al d best.
 
Share this answer
 
Hm, Based on your result it looks like you actually store the dates in a varchar field, don't. Modify the column type to date (or datetime if you need) and the query you have already written works correctly.

To test the usage of date datatype you can try running this:
SELECT MAX( CONVERT(DATE, DateOf_joining, 103) ) 
FROM  Employee

That would convert your string to dates and get the maximum
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900