PHP Date and Time


syntax:


   date ( format, [time stamp] );


  ex.: 


  echo date('F j, Y');   // january 21, 2004

  echo date('H:i');   // 23:14

  echo date('D');   // mon


  To get the current date and time stamp value use : getdate(); 


  ex.: 


  $dates = getdate();

  echo $dates['month'];   // january



Date Function Formats


  • Y year value at 4 digits
  • y year value at 2 digits
  • n month as one(1) or two(2) digits
  • m month value as two(2) digits only
  • F month as word (whole)
  • M month as 3 characters g hour, 12-hour as 1 or 2 digits
  • h hour, 12-hour as 2 digits display
  • i minutes value a am or pm words A AM or PM s seconds as 2 or 1 digits display
  • j day of the month as 1 or 2 digits display
  • d day of month as two(2) digits display l (lower case L) day of the week

getdate() array


  • year year as 4 digits
  • mon month
  • month month name as words
  • mday day of the month
  • weekday day of the week (words)
  • hours hours as two(2) digit display
  • minutes minutes as one(1) or two(2) digit display

Sample code


  echo '< select name="year">;

  if (!isset($year)){

          $year = date('Y');

  }