When debugging code that stores date/time values in a database, you may find yourself wanting to know the date/time that corresponds to a given unix timestamp, or the timestamp for a given date & time.
All conversions are done for your locale/time zone.Someone may find this info of some use: Rules for calculating a leap year:1) If the year divides by 4, it is a leap year (1988, 1992, 1996 are leap years)2) Unless it divides by 100, in which case it isn't (1900 divides by 4, but was not a leap year)3) Unless it divides by 400, in which case it is actually a leap year afterall (So 2000 was a leap year).In practical terms, to work out the number of days in X years, multiply X by 365.2425, rounding DOWN to the last whole number, should give you the number of days.The result will never be more than one whole day inaccurate, as opposed to multiplying by 365, which, over more years, will create a larger and larger deficit.This date Diff() function can take in just about any timestamp, including UNIX timestamps and anything that is accepted by strtotime().
It returns an array with the ability to split the result a couple different ways.
I built this function to suffice any datediff needs I had. negative integers are returned * * $split recognizes the following: * 'yw' = splits up years, weeks and days (default) * 'y' = splits up years and days * 'w' = splits up weeks and days * 'd' = total days * * examples: * $dif1 = date Diff() or date Diff('yw') * $dif2 = date Diff('y') * $dif3 = date Diff('w') * $dif4 = date Diff('d') * * assuming date Diff returned 853 days, the above * examples would have a print_r output of: * $dif1 == Array( [y] = I needed a way to display an announcement on a shopping site, that would warn users that orders placed between a certain date range, would not be shipped until after a certain date.
I created this simple date detection code to display the notice on certain pages.
You can just copy the code and save it to a file on the site and include it anywhere you need to perform a function, or display a notice./* Code to show a message only for a certain time frame.
This is a simple include file that can be used to display a message on any pages that use it.
Simply us a standard include instruction to this file on the page/s where you want the notice to appear.