PHP Date and Time Date and time Tutorial
Posted on: April 14, 2006 at 12:00 AM
What time is it? How many seconds have passed since the UNIX Epoch started? Learn How to use PHP Date and Time functions.

Date and time

Learn how to use PHP Date and Time functions

To get formatted date and time value you can use date() function. It is very easy to pass any format you want to get formatted time output.
string date(string format, int timestamp);
     - format: represents output string format (read below)
     - timestamp: date and time value you want to output, in special number format. If you omit this argument, function will take current date and time value.


Here are special meanings of some symbols which you can use in format string (first parameter)

* d - day of the month, numeric, 2 digits (with leading zeros)
* D - day of the week, textual, 3 letters; i.e. "Fri"
* F - month, textual, long; i.e. "January"
* h - hour, numeric, 12 hour format
* H - hour, numeric, 24 hour format
* i - minutes, numeric
* j - day of the month, numeric, without leading zeros
* l (lowercase 'L') - day of the week, textual, long; i.e. "Friday"
* m - month, numeric
* M - month, textual, 3 letters; i.e. "Jan"
* s - seconds, numeric
* S - English ordinal suffix, textual, 2 characters; i.e. "th", "nd"
* Y - year, numeric, 4 digits
* w - day of the week, numeric, 0 represents Sunday
* y - year, numeric, 2 digits
* z - day of the year, numeric; i.e. "299"
You can include any other symbols in format string and they should be outputted as they are. Only above symbols are replaced with their time and date values.
Examples:
    print(date( "l dS of F Y h:i:s" ));
Output:
    Friday 04th of January 1994 3:52:31

    print(date("Current time is: H (hours), i (minutes), s (seconds)"));
output:
    Current time is: 12 (hours), 34 (minutes), 13 (seconds)

mktime - get timestamp for date and time value
Syntax: int mktime (int hour, int minute, int second, int month, int day, int year);

Timestamp has been created to represent date / time value as a single integer number. So any logical date and time can be converted and used as special integer called timestamp. That's how you are able to compare two time moments as just two integer numbers. This timestamp contains the number of seconds between the Unix Epoch (January 1 1970) and the time specified. For example, January first of 1997th year will be less number than January second of that year.
In databases the date type fields usually stored as timestamp integers. So to create query to get all records in specified time period you can use mktime() function to get the boundary timestamp integers. If you combine both date and mktime function, you will be able to perform any time operation that you can imagine (and you don't need time machine or something :) )

Example:
Let's print date that happened 7 days ago:
    $m=date('m');
    $d=date('d');
    $Y=date('Y');
    print(date('Y-m-d', mktime(0,0,0, $m, $d-7, $Y)));


Note that PHP mktime()'s arguments sequence is different from standart UNIX mktime function. Most right arguments can be omitted and they will be set to current date time values. ьktime also would make all needed corrections if after ariphmetic calculations you would get incorrect date, for example 32nd of Febrary :).
Example. All lines print "Jan-01-1998".
    print(date("M-d-Y", mktime(0,0,0,12,32,1997)));
    print(date("M-d-Y", mktime(0,0,0,13,1,1997)));
    print(date("M-d-Y", mktime(0,0,0,1,1,1998)));

More Tutorials on roseindia.net for the topic PHP Date and Time Date and time Tutorial.
PHP Date and Time
 The PHP Date and Time functions are very useful in manipulating the Date in your PHP program. The PHP Date and Time generates the current date and time... of PHP date function: Formatting Option
 
PHP Date and Time Date and time Tutorial
Date and time Learn how to use PHP Date and Time functions To get formatted date and time value you can use date() function. It is very easy to pass any format you want to get formatted time output. string date(string format, int
 
How to convert date to time in PHP?
How to convert date to time in PHP?  Hi, programmer. The PHP..., but as a readable date and time, it leaves much to be desired. Luckily, the PHP... google search and found some PHP Date time scripts listed on the page. Glad
 
PHP Display date and time
PHP displaying the time and date into your timezone  ...() function in PHP, it doesn't display the correct time and date for their region... Returns the formatted date string Example 1: <?php ECHO "<
 
PHP Date and Time
PHP Date and Time The PHP Date and Time function is massively used... the functions of the software. ADS_TO_REPLACE_1 The PHP date and Time functions allow you to access the date and time from the server where your PHP scripts
 
PHP Displaying the date and time in your timezone Tutorial
PHP Date Time Zone       In PHP Date Time Zone class displays the time of different time zone, along with time it is also capable of displaying the longitude, latitude and comment
 
PHP Date and Time Functions
The PHP Date and Time Functions functions allows the developer to read... to manipulate the date object in the PHP code. Here is the some of the examples of PHP Date and Time Functions.ADS_TO_REPLACE_1 Printing amount of seconds
 
time conversion - Date Calendar
time conversion  hoe to add time in php like 01:30:00 and 00:45:20 and 02:50:40
 
Add Date Time together
Add Date Time together  I want to add datetime with time and result must be datetime. i am unable to do please help me in php mysql but i need this in javascript. and first datetime is from the text box and another time is from
 
Date & Time
Date & Time  How to insert System Date & Time in MS-ACCESS using Java
 
Date & Time
Date & Time  How to insert System Date & Time in MS-ACCESS using Java
 
Mysql Date no Time
Mysql Date no Time       Mysql Date no Time is used to find out the current date with no time. Understand with ExampleADS_TO_REPLACE_1 The Tutorial illustrate an example 'Date
 
Mysql Date and Time
Mysql Date and Time       Mysql Date and Time is used to return the current date and time... Mysql Date and Time. To grasp this example, we use  Current_Timestamp query
 
Display PHP clock with user input date and time
Display PHP clock with user input date and time  The following PHP code displays a clock with current date and time. I want the clock to receive user input date and time. How can this be done? <?php date<em>
 
date_time_set
. Example: Changing the time of a DateTime object <?php date_default... date_time_set date_time_set alias DateTime::setTime function resets... the modified date and time.  Syntax public DateTime DateTime::setTime ( int
 
PHP Date function
PHP Date Function In this section we will show you the different formatting options available in the PHP Date function PHP date() function provides many... Time in hours with a colon (included in PHP 5.1.3)   
 
Sql Date and Time Format
Sql Date and Time Format       The Tutorial illustrate an example from the 'Sql Date and Time...; is used to  format date and time.  SYNTAX:- DATE_FORMAT(date,format)ADS
 
convert date time to int
convert date time to int  convert date time to int
 
time ()
PHP time() Function The time() returns the current time  measured...;). Syntax of time() Function in PHP time(void) Parameter of time() Function in PHP void - void is optional parameter.  Example of time
 
php date function - Date Calendar
php date function  Hi, I am new to PHP. I am trying to get date from database. But, every time the date under 1970, it changes to 1970. Im...: 1960-12-02 (type is date ) In PHP : $dob= " 1960-12-02
 
date time picker
date time picker  I have enetered a date time picker in my jsp file. there is text field before the date time picker. What should i do so... the date time picker gets opened
 
PHP date_create
was introduced in PHP 5.1.0. Description DateTime date_create ([ string $time= "now" [, DateTimeZone $timezone= NULL ]] ) Parameters time... date_create () date_create function returns new DateTime object
 
Mysql Date from Date
; Mysql  Date from Date Time in Mysql return the Current  date. Understand with ExampleADS_TO_REPLACE_1 The Tutorial illustrate..._trimestamp ( )) query that return you the current date  from date time as Date
 
php parse string to time
php parse string to time  I am looking for a solution to parse a string into a formatted date time string
 
javascript current date and time.
javascript current date and time.  How can we display current date and time using javascript?   <html> <head> <title>... with current day,date,time and GMT.You can have your own format
 
PHP date function
PHP Date() Function PHP Date() function is used to display the date and time in a précised format.  With the help of PHP date function you can format timestamp to a more readable date and time. The following example shows you how
 
Mysql Date and Time
Mysql Date and Time      ... a date time format Query in different ways. now ( )  :The below Query return you the current date in yyyy-mm-dd and time in hh:mm:ss.ADS_TO_REPLACE_1 Query
 
PHP Make Time
PHP  Make Time In PHP, mktime() funtion is used for doing date arithmetic..._TO_REPLACE_2 <?php <?phpADS_TO_REPLACE_3 //To know previous date... visit our web page http://www.roseindia.net/tutorial/php/examples
 
The PHP Date() Function
The PHP Date() Function The PHP date() function is used for formatting the date and time. It formats a timestamp (a sequence of characters representing the date and/or time at which a certain event occurred) to make more readable
 
PHP date add function
PHP Add Date function - date_add or DateTime::add function The date_add... the letter (NOT P or T) can be any amount. Example: <?php $date = new... and seconds to a DateTime object. This function works in PHP 5.3.0 and above
 
Date & TIme - Development process
Date & TIme  Hi, I asked to insert Date and Time to database with am... with time. Hi Friend, To insert the date,use the following code in your...() that will insert date with time into database. So to use this method, you have
 
time
time display only as hh:mm.  Hi. I have retrieved time from mysql...?   Here is a jsp example that fetch the time from the database..."); java.util.Date date = new java.util.Date(dbSqlTime.getTime
 
time
time format hh:mm:ss  Hi. I have retrieved time from mysql database...?   Here is a jsp example that fetch the time from the database and display..."); java.util.Date date = new java.util.Date(dbSqlTime.getTime()); out.println
 
date and time in awt(java)
date and time in awt(java)  sir, do you have an example of date in awt java which can be view over a textfield.   Display time in JTextField import java.util.*; import javax.swing.*; import java.awt.event.*; public
 
time
time  Hi. I have retrieved time from mysql database. its in th format... is a jsp example that fetch the time from the database and display in different...()){ java.sql.Time dbSqlTime = rs.getTime("tob"); java.util.Date date
 
time
time  Hi. I have retrieved time from mysql database. its in th format... is a jsp example that fetch the time from the database and display in different...()){ java.sql.Time dbSqlTime = rs.getTime("tob"); java.util.Date date
 
Get Time And Date
Get Time And Date       The Class  Date provides you  a specific instant in time... and parsing of date string. Understand with Example In this Tutorial we want
 
time
retrieved time from mysql database  Hi. I have retrieved time from.... wat to do?   Here is a jsp example that fetch the time from..."); java.util.Date date = new java.util.Date(dbSqlTime.getTime
 
PHP Date
a"); ?> Today is: <?=$today?> Read PHP Date functions tutorial. Thanks...PHP Date  Hi, How to use PHP Date functions in my PHP program? Thanks   Hi, PHP Date functions is very handy. It is used to progracess
 
Get Date and Time
() method returns current time of date type. Here is the video tutorial of "... Get Date and Time   ... current date and time in the user given format. To do all this we have first
 
Date and Time - Swing AWT
Date and Time  the following program is developed in swings ..... the main objective of this program is to 1> get a date from user 2> retrieve the current date from the system 3> hence find out the difference
 
How to add one hour in php date?
How to add one hour in php date?  I have a date variable in PHP and I... date? Thanks   Hi, You should convert the date into time and then add... it to date. This way you can achieve the result. $currentTime = time
 
JSP Date & Time - JSP-Servlet
JSP Date & Time  Hi! How to compare a String with System time in JSP.... pls... help me... Thanks in advance
 
Maven Repository/Dependency: nz.co.senanque | madura-date-time
-date-time. Latest version of nz.co.senanque:madura-date-time dependencies. # Version Release Date You can... to create Maven Web Application in Eclipse? Maven 3 Tutorial Convert Maven
 
date_sunrise
  date_sunrise date_sunrise function returns time of sunrise for a given day and location.  Description on PHP Date Sunrise Function mixed... in hours <?php date_default_timezone_set('Europe/London'); $datetime = date
 
Current Date and Time

 
Current Date and Time

 
Mysql Date Arithmetic
in current date and time. Understand with ExampleADS_TO_REPLACE_1 The Tutorial..., we  run the select now ( ) query that return you the current date and time... date and time mysql> Select now(); Output
 
date format to be updated with current date time
date format to be updated with current date time  package LvFrm...; JButton b1,b2; //for date month year entry String strD[]={"Day","1...); /*for date entry & adding date into panel 2 also addind panel
 
Mysql Date Format
Mysql Date Format       The different types of time data in MySQL :TIME, DATE TIME and TIMESTAMP. The Tutorial helps you to write the Date Format in SQL Query.  date_format
 
Ads

Related Tags for PHP Date and Time Date and time Tutorial:


Ads

 
Advertisement null

Ads