Advertisement
Guest User

Dates Problem

a guest
Jul 1st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <?php
  2. if(isset($_GET['commands']) && isset($_GET['format']) && isset($_GET['date'])){
  3.     $date = $_GET['date'];
  4.     $outputFormat = $_GET['format'];
  5.     $commands = $_GET['commands'];
  6.  
  7.     $date = DateTime::createFromFormat('d/m/Y', $date);
  8.  
  9.     $commands = array_map('trim', explode("\n", $commands));
  10.  
  11.     for ($i = 0; $i < count($commands); $i++) {
  12.         $commandArgs = explode(" ", $commands[$i]);
  13.         $value = $commandArgs[1];
  14.         $command = $commandArgs[0];
  15.  
  16.         if($command == "add"){
  17.             $date -> add(new DateInterval("P".$value."D"));
  18.         }
  19.         else{
  20.             $date -> sub(new DateInterval("P".$value."D"));
  21.         }
  22.     }
  23.  
  24.     echo $date->format($outputFormat);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement