Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

date() function

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

date() function

Postby xlordt » Mon Jan 20, 2003 4:21 am

im tring to create this script that.. if today is the 20 then echo this.. but if its not the 20 then echo else... but i cant get it ..

Code: Select all
<?php

$today = date("l, j, y");
$start = date("monday, 20, 03");
echo $today;

if($today == $start){
 echo "<Br>YaY the day has come!";
}else{
   echo "<Br>You have to wait till the 20th to access this code";
}


?>


can anyone tell me how do i go by this.. thanx
User avatar
xlordt
New php-forum User
New php-forum User
 
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ

Postby Imaginatorium » Tue Jan 21, 2003 7:17 am

You have:

if($today == $start){

This compares the two *timestamps*, and matches only if they're exactly equal (to the millisecond), which almost never happens. You have to find out how to extract the "Day" value from the timestamp and compare it with 20.
Imaginatorium
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Jan 21, 2003 7:06 am
Location: Sano, Japan

Postby xlordt » Tue Jan 21, 2003 7:45 am

err and how do i do that... any hints..
User avatar
xlordt
New php-forum User
New php-forum User
 
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ

Postby Imaginatorium » Tue Jan 21, 2003 9:12 am

Well, look at date() in the manual at php.net. (Search function above doesn't unfortunately seem to be working.)

There's function for printing with a format string, and if you set the format to "D" (or whatever: check!), you'll get a string with the day of the month in. Check that against 20 - I only started learning php a couple of days ago so I've forgotten (again!) already how to compare strings with integers.
Imaginatorium
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Jan 21, 2003 7:06 am
Location: Sano, Japan

Postby xlordt » Tue Jan 21, 2003 9:15 am

ahh i c what your saying.. ok thanx.. i will search the manual .. and i think you have to use.. stcmp() to compare the strings.. but anyways.. i will go and check.. thanx
User avatar
xlordt
New php-forum User
New php-forum User
 
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ

Re: date() function

Postby WiZARD » Wed Jan 22, 2003 8:48 am

Hi!
If you want what i'm solve youre problemdo next:
Code: Select all
<?php

$today = date("l, j, y");
$start = date("Monday, 20, 03");
echo $today;

if($today == $start){
 echo "<Br>YaY the day has come!";
}else{
   echo "<Br>You have to wait till the 20th to access this code";
}


?>


or this:
Code: Select all
<?php

$today = date("l, j, y");
$start = ("Monday, 20, 03");
echo $today;

if($today == $start){
 echo "<Br>YaY the day has come!";
}else{
   echo "<Br>You have to wait till the 20th to access this code";
}


?>


P.S. you no need about timestamp cause you compare simple string :!: :wink:
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron