/    Sign up×
Community /Pin to ProfileBookmark

Different Output Depending on Date

hi i am currently converting one of my sites to php some of the functions are stilljavascript heres one

[code]
Date.prototype.toDateString = function () {return [this.getDate(), [‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, ‘Jul’, ‘Aug’, ‘Sep’,’Oct’, ‘Nov’, ‘Dec’] [this.getMonth()], this.getFullYear()].join(‘ ‘)}

daysOfNote = new Object();
daysOfNote[‘1 Jan’] = ‘Blah Blah’;

daysOfNote[’31 Jan’] = ‘Foo Foo’;
document.write(daysOfNote[new Date().toDateString()] ? ” + daysOfNote[new Date().toDateString()] : ‘Quote Database Not Yet Completed’);
[/code]

it displays the days note depending on what day it is, now i would like to do a similar thing in php but only take into consideration the date eg 31 not month i have tried to methods both failed 😑

[code=php]
<?php
$date_array = getdate(); // no argument passed so today’s date will be used
foreach ( $date_array as $key => $val ) {
print “$key = $val<br>”;
}
?>
<?php
$day = array(“0” “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “11”, “12”, “13”, “14”, “15”, “16”, “17”, “18”, “19”, “20”, “21”, “22”, “23”, “24”, “25”, “26”, “27”, “28”, “29”, “30”, “31” );
print $day[$date_array[‘mday’]];
?>[/code]

[code=php]
<?php
$day = array(“0” “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “11”, “12”, “13”, “14”, “15”, “16”, “17”, “18”, “19”, “20”, “21”, “22”, “23”, “24”, “25”, “26”, “27”, “28”, “29”, “30”, “31” );
print $day[‘mday’];
?>
[/code]

could someone please help me out

Thanks96

to post a comment
PHP

10 Comments(s) ↴

Copy linkTweet thisAlerts:
@PittimannJan 15.2004 β€”Β Hi!

Here you'll find the parameters for the php date function:

http://de3.php.net/manual/en/function.date.php

That should help you out...

Cheers - Pit
Copy linkTweet thisAlerts:
@96turnerriauthorJan 15.2004 β€”Β ok thanks for that ive worked out i need 'j' now how would i encorperate that into what ive got or make a new one? sorry but im really new to php started yday
Copy linkTweet thisAlerts:
@YoNJan 15.2004 β€”Β Try [code=php]<?php
echo date("j");
?>[/code]
That will display the day of the month with out leading zeros for the current server's time.

Is that what you want? ?
Copy linkTweet thisAlerts:
@96turnerriauthorJan 15.2004 β€”Β thanks yeah i guessed that, but what i would like is

<?php echo date("j"); ?> but if it is lets say that returns 22 so its 22nd 22 is not written say a quote or saying is displayed and if its 11th a different quote or saying is displayed, so a different thing is displayed for each day of month so array would need 31 elements

96
Copy linkTweet thisAlerts:
@YoNJan 15.2004 β€”Β Ohh! In that case you will want to use "jS" ?:
[code=php]<?php
echo date("jS");
?>[/code]
Copy linkTweet thisAlerts:
@96turnerriauthorJan 15.2004 β€”Β so this right?

[code=php]
<?php
$day = array("0" "1st Quote", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15th Quote", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31st Quote" );
print $day['js'];
?>
[/code]
Copy linkTweet thisAlerts:
@YoNJan 15.2004 β€”Β Nope, just use the code I gave you. That should do it. You don't need to make an array, [URL=http://www.php.net/manual/en/function.date.php]date()[/URL] does what you are trying to do.
Copy linkTweet thisAlerts:
@96turnerriauthorJan 15.2004 β€”Β ok thanks, but i cant see how thats it, because how does it know what i want to be outputted? i dont think you understand what im trying to do (no offense)

Thanks

96
Copy linkTweet thisAlerts:
@PittimannJan 15.2004 β€”Β Hi!

Try this:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
$day = array("x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31");
;
print date("j").'<br>'; //day of months
print $day[date("j")-1]; //string taken from array
?>
</body>
</html>
[/code]

Cheers - Pit
Copy linkTweet thisAlerts:
@96turnerriauthorJan 16.2004 β€”Β tyvm works a treat, couldnt get it to work at first, and couldnt see why then relised that the old one i first tried was still on server not the new one i made having a bit of trouble with ftp atm ? so didnt change to newer version :mad:

Cheers

Rich
Γ—

Success!

Help @96turnerri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 β€” BETA 5.18,
whats_new: community page,
up_next: more Davinciβ€’003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciβ€’003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...