answersLogoWhite

0


Best Answer

By calling time() you can get the current system time as a UNIX timestamp (that is, measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)).

The usual time zone and minute length complications apply.

If you need to, you can format this into a string of text (will be understandable for humans using the Gregorian solar calendar) by calling date(...) with some useful parameters. For example:

date("r", time()) will return a string in RFC2822 format, as used by E-Mail, denoting the current system time.

date("c", time()) will return a string in ISO8601 format, as used by most database management systems for date display and input, denoting the current system time.

There are all kinds of extra formats, see

User Avatar

Wiki User

17y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you retrieve the current date and time in PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is gm date in php?

Gm date is used to return date and time in UTC/GMT format.


How do you get the day of the week with php?

Following code will give you current day of the week (monday, Tuesday and so on):$day = date ('l', time());If you want more information on this topic, you can search php.net for function "date()" which formats timestamp in a way you want and "time()" which returns current timestamp.


In how many ways can you retrieve the date in the result set of MySQL using PHP?

If you store MKTIME or date("z") then there are unlimited ways.Simply usedate("d/m/Y",$mymktime);With anything at the beginning for the format.


How do you change the current directory in PHP?

chdir() PHP function helps in changing the current directory.


Insert date on web page?

Using PHP: <?php echo date("d/m/y"); ?>


What is zenith in date sunset function in PHP?

Zenith in the date sunset function in PHP refers to the angle of the sun below the horizontal plane during sunset. It is used to calculate the precise time when the sun sets based on the specific angle chosen. A lower zenith value indicates a later sunset time, while a higher zenith value means an earlier sunset time.


How do you compare current date to date in php?

Here is the code


Is there an event in PHP?

By an event I assume you mean a pre determined page of code that you can run at a specific date and time. In the language PHP, the answer is no. You cannot do this. On most Linux / Unix servers that use PHP, you can create a cron job that will run your code at a given date and time. When you put in the page address, make sure you use the full root address or it will not run.


How do you retrieve username and password from sql database to HTML web page?

You would need to use PHP


How do you echo date plus php?

Your question isn't quite clear but I think you mean this: <?php echo date("m-d-Y"); ?>


What is an example PHP script that would display a digital clock?

This question is ambiguous to completely answer, because displaying a digital clock has different interpretations. In the following, a digital clock is assumed to be 2 digits for the hours and 2 digits for the minutes with a colon in between, styled at your discretion to look like a digital clock.If you want to display the time statically as of the page loading, grab the current time() and throw it into date($format, $time). The time() function will retrieve the current time in seconds from the Unix Epoch (1/1/1970). The date() function will take this timestamp and format it, according to the format string given. See the related link for complete documentation on possible formats. The following example works fine:$time = time();$format = 'h:i A'; // "h" is the current hour, "i" the current minute, and "a" AM or PM.echo date($format, $time);This will effectively output the time as a digital clock would. You may change the format to alter how the hours and minutes are displayed, and even provide more (or less) information about the current time.If you want to display the time and have it dynamically update to reflect the current time, you will need to use Javascript -- which is out of the scope of this question.


What is PHP used for?

PHP is a programming language that is used to generate dynamic web pages based on user requests and other data that changes such as store inventory, current news, or time of day.