Hi everyone

I have a reminder email that's triggered by a cron job and reminds clients to renew their certification. The problem is that the script gets a date from a database and displays it in the email in a nonsensical way, for example:

Dear Carol Green,
We are writing to remind you that you last
completed our Online Anaphylaxis on 1297296000.

I'm assuming this is the unix time stamp. How do I convert this into human readable form. I've included the php script below:

require_once('_inc/config.php');
require_once ('_inc/ecg_con.php');
require_once ('mail.php');

$todayDate = date("Y-m-d");// current date
//echo "Today: ".$todayDate."<br>";


//Add one Year to today
//$dateOneYearAdded = strtotime(date("Y-m-d", strtotime($todayDate)) . "-1 year");

//echo "After adding one Year: ".date('l dS \o\f F Y', $dateOneYearAdded)."<br>";

$duedate= strtotime ( '-1 year' , strtotime ( $todayDate) ) ;
//$duedate = date ( 'Y-m-d' , $duedate );
//echo "due date is : ".$duedate."<br>";

$result = mysql_query("SELECT * FROM clients");

// Fetch and print all records.
    while ($row = mysql_fetch_array($result)) {
    $expiration_date = strtotime($row['enrolled']);
     if($expiration_date <$duedate)
     {
     //echo'<strong>Client Email:<br /></strong>'. $row['email']. " " .$row['course'];
      if($row['course']==$item_name1)
      {
      $renew_course_purchase_page=$renew_course1_purchase_page;
      }
      else
      {
      $renew_course_purchase_page=$renew_course2_purchase_page;
      }

 $renew_course_purchase_page=$renew_course1_purchase_page;
  //send reminder email to overdue clients

 //=================Edit Email body======================================================
  $body="Dear ".$row['fname']." ".$row['lname'].",<br>";
  $body .="We are writing to remind you that you last completed our ". $row['course'] ." on ". $expiration_date .".<br><br>";
  $body .="The Resuscitation Council recommend annual updates for all staff involved in giving vaccines and medications.";
  $body .="Please follow the below link below to make a new purchase of the course :<br>";
  $body .= $renew_course_purchase_page."<br><br>";
  $body .="Please <a href='mailto:'>Contact us</a> if you do not want anymore reminders<br><br>";
  $body .="Thank you for selecting xxxx.";

 // echo $body;        
mailmessage_nonsmtp($row['email'], $email_reminder_subject, $body, "html", $support_email_address, $support_bcc); } }

Any help on this would be really appreciated

Many thanks

    Assuming it is a Unix timestamp (so that 1297296000 refers to 10 February 2011): [man]date[/man].

    The question may be asked why the database is using a Unix timestamp instead whichever of MySQL's own date/time types is appropriate.

      Thanks for responding Weedpacket, yes it is a Unix time stamp and I think I've solved that little problem by tweaking the script like so...

      
      // From this
      $expiration_date = strtotime($row['enrolled']);
      
      // To this
      $expiration_date = $row['enrolled'];
      
      

      Why on earth the code had the 'strtotime' there I do not know, any suggestions on how to improve on the complete code or any glaring mistakes, I would really appreciate it. Thank you.

        Write a Reply...