A time difference function that outputs the time passed in facebook's style: 1 day ago, or 4 months ago. I took andrew dot macrobert at gmail dot com function and tweaked it a bit. On a strict enviroment it was throwing errors, plus I needed it to calculate the difference in time between a past date and a future date.

Below, a function to create TNG-style stardates, taking 2009 to start stardate 41000.0. In fact, the offset is trivial to adjust if you wish to begin from a different date.

<?phpfunction getStardate(void){$offset = 2000;$seconds_per_stardate = 31449.6; // is the number of seconds in a year divided by 1000, for hopefully obvious reasonsreturn time() / $seconds_per_stardate + $offset;}?>

Other series use less reliable stardate formats, which makes it difficult [read: nigh impossible] to create a function that converts a unix timestamp into a stardate.

I did an article on floating point time you can download from my website. Roun movements is the radial ounion movement and there is a quantum ounion movement as well, this code will generate the data for http://www.chronolabs.org.au/bin/roun-time-article.pdf which is an article on floating point time, I have created the calendar system as well for this time. It is compatible with other time and other solar systems with different revolutions of the planets as well as different quantumy stuff.

Here's one way to generate all intermediate dates (in mySQL format) between any 2 dates.
Get start and end dates from user input, you'd need to do the basic validations that :
- start and end dates are valid dates
- start date <= end date.

This is another function to calculate the difference between two times and output it in a relative format. This one, however, combines various units. In other words, it will return "3 days, 2 hours, 6 minutes, and 2 seconds ago" instead of "3 days ago."

Please bear in mind that it is intended for times that are very close together. It will not be accurate for calculating dates more than a month apart. This is because one of the units it relies on is "weeks," which do not correspond directly with months. What I'm trying to get across is, the program assumes that a month is precisely 4 weeks long, i.e. 28 days. This also means that a "year" according to this function is 336 days.

The function rel_time() accepts two parameters: $from and $to. For best results, provide them as UNIX timestamps (derived from PHP's time() function). They also accept formats supported by strtotime(). $to is an optional argument and defaults to the current time.

The function will calculate the difference between $from and $to. If $from occurs after $to, the function will substitue "ago" with "from now."

// Make the entered date into Unix timestamp from MySQL datetime field

$datefrom = strtotime($datefrom);

// Calculate the difference in seconds betweeen // the two timestamps

$difference = $dateto - $datefrom;

// Based on the interval, determine the // number of units between the two dates // From this point on, you would be hard // pushed telling the difference between // this function and DateDiff. If the $datediff // returned is 1, be sure to return the singular // of the unit, e.g. 'day' rather 'days'

break;// If difference is greater than or equal to 365 // days, return year. This will be incorrect if // for example, you call the function on the 28th April // 2008 passing in 29th April 2007. It will return // 1 year ago when in actual fact (yawn!) not quite // a year has gone bycase(strtotime('-1 year', $dateto) >= $datefrom):$year_difference = 1; while (strtotime('-'.$year_difference.' year', $dateto) >= $datefrom) {$year_difference++; }

Always use plural it will auto correct on singular results. You don't have to include all %d,%m,%h you may include only one. To get Total Hours remaining(including days) use %ho. To get Total Minutes remaining(including hours and days) use %mo. Take a look at the format I assumed to make any changes.

When dealing with the results of the time function, taking the modulus (remainder) is often a good way to find recurring information such as day of the week, week of the year, or month of the year. In the example given below of a firefighter's shift, you could do the following to simplify the code.

//This is the where we divide the current time since reference by the amount of time in all shifts //The result of this is the remainder.$sinceReference = (time() - $referencePoint) % (60 * 60 * 24 * 3);

The documentation says 'Return current Unix timestamp'. The definition itself of the unix time shows that it is independent of the timezone so it is obvious that this function will return the same value for the different timezones.