Home Techindex PHP Date and Time Date and time Tutorial

 
 

PHP Date and Time Date and time Tutorial
Posted on: April 14, 2006 at 12:00 AM
Advertisement
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 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
 
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 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... the formatted date string Example 1: <?php ECHO "<b>Date using
 
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 Date and Time
PHP Date and Time The PHP Date and Time function is massively used... the functions of the software.  The PHP date and Time functions allow you to access the date and time from the server where your PHP scripts are running
 
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... (if any) of the country. Example: <?php //To instantiate an object $time
 
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 Example The Tutorial illustrate an example 'Date no Time' in Mysql
 
PHP Date and Time Functions
The PHP Date and Time Functions functions allows the developer to read... of the examples of PHP Date and Time Functions. Printing amount of seconds passed since January 1 1970 00:00:00 GMT: <?php print time(); ?> Printing current date
 
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
 
Mysql Date and Time
Mysql Date and Time       Mysql Date and Time is used to return the current date and time. Understand with Example The Tutorial illustrate an example from Mysql Date
 
time conversion - Date Calendar
time conversion  hoe to add time in php like 01:30:00 and 00:45:20 and 02:50:40
 
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
 
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
 
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>
 
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
 
convert date time to int
convert date time to int  convert date time to int
 
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
 
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
 
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
 
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
 
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
 
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. Query for displaying
 
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
 
Mysql Date from Date
; Mysql  Date from Date Time in Mysql return the Current  date. Understand with Example The Tutorial illustrate an example from 'DateTime... that return you the current date  from date time as Date field name
 
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
 
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
 
PHP Make Time
PHP  Make Time In PHP, mktime() funtion is used for doing date arithmetic...://www.roseindia.net/tutorial/php/examples/PHPDatefunction.html echo "<b>... mktime ([ int $hr= date("H") [, int $min= date("i") [, int $sec
 
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
 
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
 
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...; it is tenth month of the year PHP Date formatting example code: <?php
 
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 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
 
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
 
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
 
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
 
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... amount. Example: <?php $date = new DateTime("24-Aug-2009 13:10... and seconds to a DateTime object. This function works in PHP 5.3.0 and above
 
Current Date and Time

 
Current Date and Time

 
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
 
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
 
Display Date and Time - Design concepts & design patterns
system date and time . Thanks Prakash  Hi Friend, Try the following code: System Date and Time var date = new Date(); document.write("System date and Time is: "+ date); Thanks
 
updated with current date n time
updated with current date n time  package LvFrm; import...; //for date month year entry String strD[]={"Day","1","2","3","4","5...); panel2.setBorder(b2); frm.add(panel2); /*for date entry
 
J2ME Current Date And Time
J2ME Current Date And Time     ... the current date and time on the screen. Like core Java J2ME too use the same  java.util package to show the current date as well as current time on the screen
 
Mysql Date Arithmetic
in current date and time. Understand with Example The Tutorial illustrate... the select now ( ) query that return you the current date and time. SYNTAX:-date + INTERVAL expression unit Query:- For current date and time mysql>
 
Get current Date and Time
Get current Date and Time In this section we will discuss about how to get current date and time in java. Java provide two classes, Date and calendar which will display the current date and time in java. SimpleDateFormat is used 
 
Mysql Date Now
; Date Now in Mysql is used to find out the current date and time. Understand with Example The Tutorial illustrate an example from 'Mysql Date Now'. In this example we help you to find out the current date and time in Mysql. The Syntax below
 
Advertisement

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


Advertisements Advertisements
 

 

 

DMCA.com