#native_company# #native_desc#
#native_cta#

Date Manipulation in Php

By Allan Kent
on July 30, 2000

I was sitting writing a kind of helpdesk call management program in
PHP and found that I needed to work out how much time had elapsed
since somebody had last bothered to contact the client about their
problem. In the past, when I used to use ASP, the solution was simple –
ASP has a command called DateDiff which takes two dates and can tell
you how many seconds has passed between them, how many days, months and
so on. After scouring the PHP manual for a while I decided that PHP has
no such beast. I then wondered how many other people there were out
there like me, and thus this tutorial.
Ok, so what are we going to cover?
  1. Getting the current date and time – what options do we have ?
  2. Changing the way the date is displayed – date and time formatting
  3. Converting existing dates into Unix timestamps
  4. Back to the future – modifying the date
    1. Adding time to the current date
    2. Subtracting time from the current date
    3. Working out the time between two dates
  5. Creating a DateAdd function for PHP

  6. Creating a DateDiff function for PHP

1
|
2
|
3
|
4
|
5
|
6
|
7