PHP Date Function & Example

PHP Date() Function Description

this function give result for date format, convert date format.
Returns a string formatted according to the given format string using the given integer timestamp can be using to convert databases date format.

Using PHP Function Format Date

Example using date() format

  1. <?php
  2. echo date("Y/m/d") . "<br />";
  3. echo date("Y.m.d") . "<br />";
  4. echo date("Y-m-d")
  5. ?>

OutPut

  1. 2009/05/11
  2. 2009.05.11
  3. 2009-05-11
  4.  

For spesific you date using time you can using mktime() for more option time : Second, Minute, Hour, Day, Month and Year

  1. mktime(hour,minute,second,month,day,year,is_dst)
  2.  
  3. <?php
  4. $tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
  5. echo "Tomorrow is ".date("Y/m/d", $tomorrow);
  6. ?>
  7.  
  8.  
  9. You can get output tomorrow time

For change type format you can see this table :

format character Description Example returned values
Day
d Day of the month, 2 digits with leading zeros 01 to 31
D A textual representation of a day, three letters Mon through Sun
j Day of the month without leading zeros 1 to 31
l (lowercase 'L') A full textual representation of the day of the week Sunday through Saturday
N ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday)
S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
z The day of the year (starting from 0) 0 through 365
Week
W ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) Example: 42 (the 42nd week in the year)
Month
F A full textual representation of a month, such as January or March January through December
m Numeric representation of a month, with leading zeros 01 through 12
M A short textual representation of a month, three letters Jan through Dec
n Numeric representation of a month, without leading zeros 1 through 12
t Number of days in the given month 28 through 31
Year
L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
o ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0) Examples: 1999 or 2003
Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
y A two digit representation of a year Examples: 99 or 03

Source table : http://php.net/

Posted by admin   @   7 November 2009
Tags : ,

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« jquery image slider | slideshow Images and Content
Next Post
wordpress permalink 404 error not found »
Powered by Wordpress   |   Lunated designed by ZenVerse
Top Footer