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

Number Search Volume 10

$7.99      buyNow
Over 150 fun family friendly challenging number search puzzles (with answer sheets). This volume focuses on random number words between 100000 thru 109999. Minimum of 40 number words per puzzle. Each puzzle is on its own page, which not only reduces crowding but also allows for larger word print sizes for easier reading. Answer sheets for each puzzle are provided in the back of the book. Fun for yourself and for the entire family. This makes for a great gift idea as well.

Date and Time



Today is : Thursday Mar 23, 2023 06:41:57 pm

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 23
The day (D) is Thu
The month (m) is 03
The month (M) is Mar
The year (y) is 23
The year (Y) is 2023
Today (l) is Thursday
Today is 2023/03/23
Today is 2023.03.23
Today is 2023-03-23
Today is Thursday Mar 23, 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 18
The hour (h) is 06
The minute (i) is 41
The second (s) is 57
The meridiem (a) is pm
The meridiem (A) is PM
The current time is 06:41:57 pm


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.


grayStargrayStargrayStargrayStargrayStar  Be the first to rate this post

User Comments






TJDivisions© 2023