Showing posts with label DATE. Show all posts
Showing posts with label DATE. Show all posts

Saturday, September 12, 2015

PHP get previous date

The following function gives the previous date of the date entered.

For date format: 2014-02-15

function prevDate($date)
  {
 $dateArray=explode('-',$date);
 $tomorrow = mktime(0,0,0,$dateArray[1],$dateArray[2]-1,$dateArray[0]);
 return date("Y-m-d", $tomorrow);
  }
 
  Usage of the function is as follows:
 
  $date = "2014-02-15";
 
  echo prevDate($date);
 
  Ouput is: 2014-02-14
 
For date format: 2014/02/15

function prevDate($date)
  {
 $dateArray=explode('-',$date);
 $tomorrow = mktime(0,0,0,$dateArray[1],$dateArray[2]-1,$dateArray[0]);
 return date("Y-m-d", $tomorrow);
  }
 
  Usage of the function is as follows:
 
  $date = "2014/02/15";
 
  echo prevDate($date);
 
  Ouput is: 2014/02/14

PHP get next date of the current date

The following function gives the next date of the date entered.

For date format: 2014-02-15

function nextDate($date)
  {
 $dateArray=explode('-',$date);
 $tomorrow = mktime(0,0,0,$dateArray[1],$dateArray[2]+1,$dateArray[0]);
 return date("Y-m-d", $tomorrow);
  }
 
  Usage of the function is as follows:
 
  $date = "2014-06-01";
 
  echo nextDate($date);
 
  Ouput is: 2014-06-02
 
For date format: 2014/02/15

function nextDate($date)
  {
 $dateArray=explode('/',$date);
 $tomorrow = mktime(0,0,0,$dateArray[1],$dateArray[2]+1,$dateArray[0]);
 return date("Y-m-d", $tomorrow);
  }
 
  Usage of the function is as follows:
 
  $date = "2014/06/01";
 
  echo nextDate($date);
 
  Ouput is: 2014/06/02

PHP add number of days into date

PHP supports various date types and its conversion.
The following php example demonstrate to add n number of days in the provided date.

For date format: yyyy-mm-dd

function addDate($date,$n)
  {
 $dateArray=explode('-',$date);
 $addDate = mktime(0,0,0,$dateArray[1],$dateArray[2]+$n,$dateArray[0]);
 return date("Y-m-d", $addDate);
  }
  
  Usage of the function is as follows:
 
  $n = 1;
  $date = "2014-06-01";
 
  echo addDate($date, $n);
 
  Ouput is: 2014-06-02
 
For date format: yyyy/mm/dd

function addDate($date,$n)
  {
 $dateArray=explode('/',$date);
 $addDate = mktime(0,0,0,$dateArray[1],$dateArray[2]+$n,$dateArray[0]);
 return date("Y-m-d", $addDate);
  }
 
  Usage of the function is as follows:
 
  $n = 1;
  $date = "2014/06/01";
 
  echo addDate($date, $n);
 
  Ouput is: 2014/06/02

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...