Page 1 of 1
need help with some simple php :)
Posted: Thu Jan 08, 2004 12:09 am
by stylezeca
I have a question
how would I do something to show a calendar of a certain month according to the server DATE
i wanna do something like this
if ($serverdate = october) {
include("october.html");
} elseif ($serverdate = november) {
include("november.html");
} elseif ($serverdate = december) {
include("december.html");
} else {
echo "error";
}
get what im saying? im not exactly sure how to set it up, but how would i set up a date to grab that information from according to the servers date, not the the clients date... thankyou! and if you could help to show the current month and the next month would be very helpful!
example: on the website it would show
'january' and 'february' saying that the month is january according to the servers date.
thankyou!!!
Posted: Thu Jan 08, 2004 12:14 am
by Gen-ik
Code: Select all
<?php include(strtolower(date("F")).".html") ?>
That should include() "january.html" or "febuary.html" etc depending on the servers month.
yay
Posted: Thu Jan 08, 2004 1:43 am
by stylezeca
wow works like a charm, mind explaining how it works? and how would i show the next month too? like if the month is JANUARY, how would i also make it show FEBRUARY?
thanks!
Posted: Thu Jan 08, 2004 1:54 am
by microthick
date("F") grabs the current month. For example, this month it'll be January but next month it'll be February.
Wrapping that with strtolower(), makes the month lowercase.
Then, we add .html to the month to create the file name to include.
It will always include the file for the particular month we are in.
Posted: Thu Jan 08, 2004 2:01 am
by Gen-ik
Basically the
date() function can be used to get any date/time you want... check out [php_man]date[/php_man] for all of the info but "F" will give you the month ie "January".
If you
echo date("jS F Y") that will give you something like "1st January 2004".
The
strtolower simply turns the string (in this case the name of the month) into lowercase so that you get "january".
If you want to get the next or previous month(s) you can use
strtotime() which allows to modify dates. Here's an example...
Code: Select all
<?php
// Today
echo date("jS F Y")."<br />";
// Next month
echo date("jS F Y", strtotime("+1 month", time())."<br />";
// In 500 days, 42 hours, and 600 minutes time (I think this should work)
echo date("jS F Y", strtotime("+500 days +42 hours +600 minutes", time());
?>
Good date/time type things to check out are [php_man]date[/php_man] [php_man]gmdate[/php_man] [php_man]time[/php_man] and [php_man]strtotime[/php_man]
Hope that all helps

hnnn
Posted: Thu Jan 08, 2004 2:19 am
by stylezeca
<?php include(strtolower(date("F")).".html") ?>
<?php include(strtolower(date("F",strtotime("+1 month"))).".html") ?>
would that include january and feb?
Posted: Thu Jan 08, 2004 4:29 am
by Gen-ik
You nearly got it right. You're missing the time() bit of the second line.
Code: Select all
<?php
// January
include( strtolower(date("F")).".html" );
// Febuary
include( strtolower(date("F", strtotime("+1 month", time()))).".html" );
?>

buzzzzzy
Posted: Thu Jan 08, 2004 11:11 am
by stylezeca
thanks! whats the time() part do? cause it works without it also...
Posted: Thu Jan 08, 2004 12:41 pm
by Gen-ik
time() simply gets the current server time as a unix_timestamp.
Check-out [php_man]time[/php_man] for more info.
ok
Posted: Thu Jan 08, 2004 7:57 pm
by stylezeca
ok thanks, helped a lot! but now lol
how would i go about making it grab a certain year, like when its year january 2005, how would i make it grab a different january.html maybe like january2005.html instead of january2004.html
Posted: Fri Jan 09, 2004 12:29 am
by Bennettman
You'd change the strtotime function to say "+1 year" or "-1 year" instead.
Posted: Fri Jan 09, 2004 8:19 am
by Gen-ik
You need to read (and learn) those links I posted (up the top somewhere).. that way you will be able to do this quite easily
Code: Select all
include( strtolower(date("FY", strtotime("+1 year", time()))).".html" );
That will include() the file
january2005.html.. just change "+1 year" to whatever you need to.