Previous Thread
Next Thread
Print Thread
Rate Thread
#239535 03/11/2003 12:38 PM
Joined: Jan 2003
Posts: 125
Journeyman
Journeyman
Joined: Jan 2003
Posts: 125
i'm building a report at work against a MS SQL database with financial info in it. my boss is desiring the report to take, for example, today's date, and compare it to the same "DAY" last year.

so if we ran a report for today: Tues March 11, 2003
it would compare against Tues March 12, 2002.

It seems simple except for Leap Years. Anybody have any advice on the best practice to do this. I'm thinking convert to time stamp and do some IF conditions to determine if a Leap year is involved.

Any help would be appreciated.

Chillin

Sponsored Links
kwalenta #239536 03/11/2003 2:31 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
I don't know about MS SQL, but MySQL has some column types specifically for storing dates and times. If you're using one of those, you can make use of the Date and Time Functions, such as DATE_SUB.

joeuser #239537 03/11/2003 2:44 PM
Joined: Jan 2003
Posts: 125
Journeyman
Journeyman
Joined: Jan 2003
Posts: 125
unfortunately, the dates in this particular db/tables are stored as YYYY-MM-DD, i have a stored procedure that does somethign similar as to what i'd like to do.

i'll try to hack it to work with php and post

kwalenta #239538 03/12/2003 8:28 PM
Joined: Aug 2002
Posts: 1,191
Kahuna
Kahuna
Joined: Aug 2002
Posts: 1,191
A good way to see if a year is a leap one is to divide it by 4. If the modulus is 0 then it is a leap year, hence 2000, 2004, 2008 are whereas 2001, 2002, 2003 etc. are not.


Nikos
Hal_dup2 #239539 03/12/2003 8:31 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
Actually, it is not quite that easy, but it'll be a while before that calculation won't work again. =]

Sponsored Links
c0bra #239540 03/12/2003 8:35 PM
Joined: Aug 2002
Posts: 1,191
Kahuna
Kahuna
Joined: Aug 2002
Posts: 1,191
Alternatively you can use the mcal library (http://mcal.chek.com) which introduces the mcal_is_leap_year. You pass the year as an integer and it returns true or false depending on whether the year is a leap one or not.


Nikos
Hal_dup2 #239541 03/12/2003 8:53 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
Or just this:
date("L", mktime(0,0,0,1,1,2004)) which will be true or false depending on if the year is a leap year or not.

In this case, use date("L", strtotime($datefromdb))

c0bra #239542 03/12/2003 8:57 PM
Joined: Aug 2002
Posts: 1,191
Kahuna
Kahuna
Joined: Aug 2002
Posts: 1,191
Ok I give up! LOL


Nikos
Hal_dup2 #239543 03/12/2003 8:59 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
I won!

;]


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Bill B
Bill B
Issaquah, WA
Posts: 87
Joined: December 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20240430)