need help with some simple php :)
Moderator: General Moderators
need help with some simple php :)
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!!!
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!!!
Code: Select all
<?php include(strtolower(date("F")).".html") ?>-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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.
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.
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...
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
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());
?>Hope that all helps
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" );
?>ok
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
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
-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
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 
That will include() the file january2005.html.. just change "+1 year" to whatever you need to.
Code: Select all
include( strtolower(date("FY", strtotime("+1 year", time()))).".html" );