Advertisement
cafreak

TimeStamp methods + receive date + add days to date

Jan 18th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. //set these functions in a class : else remove the public hint.
  2. public function getDate($length = 0){
  3.     $date = new DateTime(date("Y")."-".date("m")."-".date("d"));
  4.     $length = ($length == null || !(is_int($length))) ? 0 : $length;
  5.     $date = $date->add(new DateInterval('P'.$length.'D'));
  6.     return $date->format('d-m-Y');
  7. }
  8.        
  9. public function convertToTimestamp($date){
  10.     $date = explode('-', $date);
  11.     $timestamp = mktime(0, 0, 0, $date[1], $date[0], $date[2]);
  12.     return $timestamp;
  13. }
  14.        
  15. public function convertToDate($timestamp){
  16.     $date = date('d-m-Y', $timestamp);
  17.     return $date;
  18. }
  19.  
  20. //usage:
  21.  
  22. convertToTimestamp(getDate(30)); //get's converted current date with 30 days added
  23.  
  24. convertToDate($timestamp); //return the date from the timestamp using day-month-year
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement