Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Convert date without a timestamp

    I'm trying to convert a date from 0000-00-00 format to something a little nicer to read. However, I can't use the strtotime function because the year is 5 years prior to the Unix epoch. Does anyone know of a way that I can convert a date's format without a timestamp?

  • #2
    New Coder
    Join Date
    Apr 2005
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Got tired of waiting and wrote my own function.

    Code:
    function date_convert(&$date) {
      $year = substr($date, 0, 4);
      $month = substr($date, strlen($year) + 1, 2);
      $day = substr($date, strlen($year) + 4, 2);
      
      switch ($month) {
        case "01": $month = "Jan"; break;
        case "02": $month = "Feb"; break;
        case "03": $month = "Mar"; break;
        case "04": $month = "Apr"; break;
        case "05": $month = "May"; break;
        case "06": $month = "Jun"; break;
        case "07": $month = "Jul"; break;
        case "08": $month = "Aug"; break;
        case "09": $month = "Sep"; break;
        case "10": $month = "Oct"; break;
        case "11": $month = "Nov"; break;
        case "12": $month = "Dec"; break;
      }
      $date = "$month $day, $year";
      return $date;
    }

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm guessing you're using a Windows server? Most *nix servers support negative timestamps so you can take the date back to circa 1901.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •