Nov 7, 2009

Using The Date() Function [php]

free web hosting
Open Discussion > MODERATED AREA > Tutorials

Using The Date() Function [php]

shadow skazi
The date() function can be used in a good way, in some cases, and the most common place you would probably see this in use would be on forums. Let's get down to business...

If you would like to display the date, you would have to put the echo tag before the date() function as so...

CODE
echo date("g:i:s");


Which would display as the common hours, minutes, seconds format (ex: 3:32:45). But you can also add wheather it is AM or PM, display the day (Sunday thru Monday), the year, pretty much anything that has to do with date.

Here is a chart to explain what each essential(Which means I wont go over all of them) function does...

a - lowercase AM or lowercase PM
A - uppercase AM or uppercase PM
c - ISO 8601 date (PHP 5 only) Would display as: 2005-02-28T16:17:18+00:00
d - day of the month with zeroes (01 thru 31)
D - Name of the day (Mon thru Sun)
F - Displays the month (January thru December)
g - Displays the hour without zeroes (1 thru 12)
G - Displays a 24 hour format w/o zeroes [military time] (0-23)
i - minutes
m - Numeric representation of a month, with leading zeros (01 through 12)
M - A short textual representation of a month, three letters (Jan through Dec)
n - Numeric representation of a month, without leading zeros (1 thru 12)
s - seconds
z - Day of the year (0-365)
T - Timezone
Y - year (4 digit number)

Hope this helps smile.gif

 

 

 


Comment/Reply (w/o sign-up)

Dragonfly
Hi Skazi, thank alot for this. I wanted to use immediately. Since php is server side scripting, the time displayed will not adjust according to the local time (users time) but it will point the server time, is it true? If so what changes can be done? And also the date output is not CSSed or format. How can I change the stylesheet of the output. I'm quite new to php, if you can explain me a little bit more, I would be very happy. Thanks in advance.

Comment/Reply (w/o sign-up)

maddog39
What you can do for the CSS thing is just put the date into a separate file like this...

CODE

<?php
echo date("g:i:s");
?>

Then save it as date.php and in your main page or whatever just go...

CODE

<?php
include ('date.php');
?>

and then the date will show up with the stye according to your CSS file on your main page. Hope that solves your problem, always works for me. wink.gif biggrin.gif

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : date, function, php

  1. Php - Forms, Date And Include
    Working with POST and GET and also the Date() function (0)
  2. User Permission Function [php]
    Determining User Permissions (3)
    There have been several recent request for methods to restrict access to various pages on a web-site
    based on User Permissions in sites that have a Login System in place. Here is some code showing one
    method to restrict access by providing a sub-set of your site's links based on the User's
    permissions. In this demonstration, I have defined a string for each 'level of user'
    determining which set(s) of links they can view on your site. Normal MySql procedure would be to
    read the User's permission level from a record in the database. For the purpose of ....
  3. Show The Current Date/time With Php
    (1)
    CODE $date = date( F j, o ); //Displays April 25, 2007 (Assuming that is the current date)
    $time = date( g:i a );  //Displays 4:26 PM (Assuming that is the current time) echo "Welcome!  The
    date is $date and the time is currently $time."; ?> You can change the date and time formats by
    changing the text in bold above. For a complete list of time formats, visit the link below.
    http://us2.php.net/manual/en/function.date.php ....
  4. Php - Randomize Web Title
    using arrays and the random function (5)
    PHP - Randomize Web Title with the rand function... Define the variables numbers we start at number
    0 CODE $title = "Web title 0"; // Title 0 $title = "Web title 1"; // Title 1 $title =
    "Web title 2"; // Title 2 $title = "Web title 3"; // Title 3 $title = "Web title 4"; // Title 4
    ?> now we use the rand() function to get a randomize the web title. rand(0, 4) means we start at
    0 and end at 4 i can get 0,1,2,3,4 one of those. It depends how many arrays you have CODE //
    get a random number   $randomize = rand(0, 4); // Change four to how many arr....
  5. Php Sockets
    Introduction to an underused function of PHP (4)
    This tutorial is based on a question written in the PHP programming board Inspiration
    Introduction Sockets, an underused function in PHP, is a function that enables you to open
    connection to other peoples computers and vice versa. By sending commands to the operating server,
    it will first see if there's response, then, it sends or receives data that the operating server
    has available. Creation of a socket Of course, a first step in using sockets, is creating it,
    this is done by: CODE resource socket_create ( int domain, int type, int protocol) and a ....
  6. [tutorial] Delphi
    Multi-Parsing Function (0)
    I've spent a while trying to create parsing function with Delphi. This language is very useful.
    This tutorial explains how to parse multiple instances of an item in one string. Here is the
    function (which I am actually very proud of): Code: function TForm1.MultiParse(MainString,
    BeginString, EndString: string): TStrings; var PosBeginString, PosEndString, i, LastPos: integer;
    tmpCopy: string; tmpStrings: TStrings; begin tmpStrings := TStringList.Create; LastPos := 0;
    for i := 1 to LastDelimiter(EndString, MainString) do begin PosBeginString := Pos....
  7. Delphi
    Simple Text Parsing Function (1)
    Because parsing is such an integral part of string manipulation, I took the time to make a quick and
    simple parse function. For you VBers, Delphi is a derivative of Pascal...it's powerful, simple,
    and (best of all) doesn't need external component (eg: ocx files). Hence the code: Code:
    function TForm1.SimpleParse(MainString, BeginString, EndString: string): string; var PosBeginString:
    integer; PosEndString: integer; begin PosBeginString := Pos(BeginString, MainString) +
    Length(BeginString); PosEndString := Pos(EndString, MainString); Result := Copy(MainString, ....

    1. Looking for date, function, php

Searching Video's for date, function, php
See Also,
advertisement


Using The Date() Function [php]

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com