Advertisement
kofi847

PHP Carbon

Jul 30th, 2023 (edited)
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1.         use Carbon\Carbon;
  2.  
  3.         $oldDate = '2023-7-15';
  4.         $todayDate = date('Y-m-d');//Todday's date 30-07-23
  5.         $futureDate = '2023-08-3';
  6.  
  7.         $parseOldDate = Carbon::parse($oldDate);
  8.         $parseTodayDate = Carbon::parse($todayDate);
  9.         $parseFutureDate = Carbon::parse($futureDate);
  10.  
  11.        
  12.           if ($parseOldDate->isPast())
  13.              {
  14.              return "this $oldDate is in the past ";    // check if date is in the past
  15.             }                                           //ouputs : this 2023-07-15 in the past
  16.  
  17.          if($parseFutureDate->isFuture())                // check if date is in the future
  18.             {
  19.              return "this $futureDate is in the future ";  // outputs: this 2023-08-3 in the future
  20.            }
  21.  
  22.         // if($parseTodayDate->isToday()){ // check if date is in the past
  23.         //     return "this $todayDate is in the today ";
  24.         // }
  25.  
  26.         /* if( date('w') !=0 && date('w') !=6)    // check if day is weekend (Saturday or Sunday)
  27.         {
  28.             return "Today is  not weekend ";
  29.         } */
  30.  
  31.        /*  if($parseTodayDate->isWeekend()){ //check if day is weekend (Saturday or Sunday)
  32.             return "Today is weekend ";
  33.         }  */
  34.  
  35.       /*   if($parseTodayDate->isWeekday()){ //check if day is weekend (Saturday or Sunday)
  36.             return "Today is weekday ";
  37.         }  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement