General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 29th, 2005, 02:20 AM
Suhan Suhan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 Suhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 34 sec
Reputation Power: 0
Compare Date fields and Display

Hi Frnds,

It will of great gesture if anyone can help me out.

Take two dates(date1, date 2) as an input,
compare them
Get the number of days between the two dates.
If Date 1> Date 2 display Date 1
If Date 1=Date 2 display Date1 and Date2
If Date 1< Date 2 display Date 2.

Cheers!!!
Suhan

Reply With Quote
  #2  
Old September 29th, 2005, 07:58 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Is this SQL, or a stored procedure?

Reply With Quote
  #3  
Old September 29th, 2005, 11:19 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Try this:

Code:
SELECT
 DATEDIFF(dd,date1,date2) AS days_no
,CASE
  WHEN date1 > date2 THEN date1
  WHEN date1 = date2 THEN CONCATENATE(date1 || date2)
  WHEN date1 < date2 THEN date2
 END AS display_date
FROM
 table


Syntax for DATEDIFF and CONCATENATE may vary slightly depending on your exact brand, but you should be able to use something close to the above.
__________________
"A pawn is the most important piece on the chessboard -- to a pawn"


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Compare Date fields and Display


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT