Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //set these functions in a class : else remove the public hint.
- public function getDate($length = 0){
- $date = new DateTime(date("Y")."-".date("m")."-".date("d"));
- $length = ($length == null || !(is_int($length))) ? 0 : $length;
- $date = $date->add(new DateInterval('P'.$length.'D'));
- return $date->format('d-m-Y');
- }
- public function convertToTimestamp($date){
- $date = explode('-', $date);
- $timestamp = mktime(0, 0, 0, $date[1], $date[0], $date[2]);
- return $timestamp;
- }
- public function convertToDate($timestamp){
- $date = date('d-m-Y', $timestamp);
- return $date;
- }
- //usage:
- convertToTimestamp(getDate(30)); //get's converted current date with 30 days added
- convertToDate($timestamp); //return the date from the timestamp using day-month-year
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement