You currently have JavaScript disabled on your browser.

This website uses JavaScript, and This page needs JavaScript activated to work correctly.

Please active JavaScript on your browser and then refresh this page.

adThumb

Word Search Spring Edition

$8.24      buyNow
Over 150 fun challenging family friendly Word Search puzzles (with answer sheets). This Spring Edition is loosely based on the "National Day Of" themes for the Spring months of March, April, and May. Two puzzles per day, One puzzle per page in efforts to reduce crowding which offers you large print for easier reading. Minimum of 40 words per puzzle. Answer sheets for each puzzle are provided in the back of the book. Fun for yourself and for the entire family.

Date and Time



Today is : Friday Sep 22, 2023 06:24:00 am

In this blog post I am referring to the Date and Time feature that is available with server side PHP.

It is important to keep in mind that since the date() function is server side PHP then the returned date and time value is that of the server, and is not that of the client. To get the clients current date and time values you would need to use JavaScript instead of PHP.

The PHP date() function formats a timestamp date into a more manageable date and/or time.

ParameterDescription
formatRequired, Specifies the format of the timestamp
timestampOptional. Specifies a timestamp. If not specified then default value used is the current date and time

Get a Date

The required format parameter of the date() function specifies how to format the date (or time).

Some commonly used date format characters include:

Other characters, such as "/", ".", or "-" can also be inserted between the characters to automatically add additional formatting to the returned value, so that the returned value looks something like "07/15/2021".

Example Source Code

This example demonstrates how to display and format today's date in a variety of different ways:

 
<?php
echo("The day (d) is " . date("d") . "<br>");
echo("The day (D) is " . date("D") . "<br>");
echo("The month (m) is " . date("m") . "<br>");
echo("The month (M) is " . date("M") . "<br>");
echo("The year (y) is " . date("y") . "<br>");
echo("The year (Y) is " . date("Y") . "<br>");
echo("Today (l) is " . date("l") . "<br>");
echo("Today is " . date("Y/m/d") . "<br>");
echo("Today is " . date("Y.m.d") . "<br>");
echo("Today is " . date("Y-m-d") . "<br>");
echo("Today is " . date("l M d, Y") . "<br>");
?>

When you run the above example then you should see something similar to the following:

The day (d) is 22
The day (D) is Fri
The month (m) is 09
The month (M) is Sep
The year (y) is 23
The year (Y) is 2023
Today (l) is Friday
Today is 2023/09/22
Today is 2023.09.22
Today is 2023-09-22
Today is Friday Sep 22, 2023


Get a Time

Like the date values, the time values can also be extracted and formated for desired use. To get the time values, you still use the PHP date() function, but you pass it different format characters that are related to time.

Some commonly used time format characters are:

Other characters, such as "/", ".", or "-" can also be inserted between the characters to automatically add additional formatting to the returned value, so that the returned value looks something similar to "8:58:13 am".

Example Source Code

This example demonstrates how to display and format the value of time in a variety of different ways:

 
<?php
echo("The hour (H) is " . date("H") . "<br>");
echo("The hour (h) is " . date("h") . "<br>");
echo("The minute (i) is " . date("i") . "<br>");
echo("The second (s) is " . date("s") . "<br>");
echo("The meridiem (a) is " . date("a") . "<br>");
echo("The meridiem (A) is " . date("A") . "<br>");
echo("The current time is " . date("h:i:s a") . "<br>");
?>

When you run the above example then you should see something similar to the following (refresh the page to see these values update):

The hour (H) is 06
The hour (h) is 06
The minute (i) is 24
The second (s) is 00
The meridiem (a) is am
The meridiem (A) is AM
The current time is 06:24:00 am


Final Thoughts

Just keep in mind that the returned date and time values are that of the web server and is not necessarily that of the client.

Thank you for reading, I hope you found this blog post (tutorial) educational and helpful.

 
(0)   (0)

grayStargrayStargrayStargrayStargrayStar  Be the first to rate this post

User Comments






TJDivisions© 2023