Blinding Light: Free Web Layouts, Anime Transparent PNG, PS Brushes, Coding Tutorials and more!

Blinding Light: Web Layouts, PS Brushes, Coding Tutorials, Transparent PNG

Date And Time

See how to display the date and time. Let's go and get started, shall we?

Step 1: Code

<?php $mydate = date("format"); ?>

Looks easy, huh? All we have to change is the italicized word, format, which I'll discuss in the next part of this tutorial.

Step 2: Format

Here are the date format symbols and their respective meaning...

SYMBOL MEANING
  M    Month in text, abbreviated. Ex: Sep
  F    Month in text. Ex: September
  m    Month in numbers with leading 0s. Ex: 09
  n    Month in numbers. Ex: 9
  d    Day of month with 2 digits. Ex: 09, 16
  j    Day of month. Ex: 9, 16
  D    Day of week, abbreviated. Ex: Fri
  l    Day of week. Ex: Friday
  w    Day of week in numbers. Ex: 0 (Sunday)
  Y    Year in 4 digits. Ex: 2004
  y    Year in 2 digits. Ex: 04
  h    12-Hour format with leading 0s. Ex: 03, 12
  g    12-Hour format. Ex: 3, 12
  H    24-Hour format with leading 0s. Ex: 03, 23
  G    24-Hour format. Ex: 3, 23
  i    Minutes. Ex: 00, 59
  s    Seconds. Ex: 00, 59
  a    am or pm in lowercase
  A    AM or PM in uppercase

Step 3: Putting It All Together

Catching on so far? We're in the last leg of this tutorial. Now that we know the syntax and date format, let's display our date!

<?php

$mydate = date("l. F j, Y. g:i:s A");

echo "$mydate";

?>

The code above will show something like this:

Sunday. May 2, 2004. 3:18:00 PM

The date and time is obtained from the operating system used.

Conclusion

Isn't that convenient? Just 2 lines of code. Have fun learning!

If you have any questions or if you want to discuss this tutorial, you may post at Blinding Light MB.

Web site design, scripting and contents © 2003-08 Miko Reznor.
No part of this site may be republished without permission.