Posted By

razel on 02/06/08


Tagged

date timestamp


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

crs0328


create_timestamp


 / Published in: PHP
 

Forms a php timestamp out of an date string i.e. create_timestamp(24.12.2007);

  1. function create_timestamp($date) { // Format : DD.MM.YYYY
  2. if (preg_match("/^([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})$/i",$date))
  3. {
  4. $expDate=explode(".",$date);
  5. if(strlen($expDate[0])=="1"){$expDate[0]="0".$expDate[0];}
  6. if(strlen($expDate[1])=="1"){$expDate[1]="0".$expDate[1];}
  7. return mktime(0,0,0,$expDate[1],$expDate[0],$expDate[2]);
  8. }
  9. else return false;
  10. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jimmayes on February 26, 2008

$date = "02.26.2008"; // Format : DD.MM.YYYY echo strtotime($date);

strtotime() is your friend ;-) http://www.php.net/manual/en/function.strtotime.php

You need to login to post a comment.