Jump to content
xisto Community
Sign in to follow this  
shadow skazi

Using The Date() Function [php]

Recommended Posts

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...

 

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 :D

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

<?phpecho date("g:i:s");?>
Then save it as date.php and in your main page or whatever just go...

<?phpinclude ('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. :D:D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.