Hi all
I need a little help creating a date function.
I’m wondering how I can print a string instead of the date, based on certain conditions.
If date = today print today
If date = tomorrow print tomorrow
and so on…
The below works and prints ‘today’ (small example of what I’m trying to do).
function print_datestrings() {
$datetoday = date('Y-m-d') == date('Y-m-d', strtotime('now'));
if ($datetoday == date('now')) {
print "today";
} else if ($datetoday == date("+1 day")) {
print "tommorrow";
} else if ($datetoday == date("-1 day")) {
print "yesterday";
} else {
print $datetoday;
}
}
print_datestrings();
Though what I really need is a function I can simply attached to a condition/variable which will check the dates and print the strings accordingly.
Today and tomorrow strings can be printing numerous times from a loop. I could have 6 events running today for example which would need to print today, maybe 4 events for tomorrow which would all print tomorrow.
Examples - which would be inside a foreach loop:
$data = print_datestrings($node->title);
or
$date = print_datestrings(date('l, j F', $timestamp));
Any suggestions, what I need to do?
Ideally, a function I can use again and again for different projects.
Thanks,
Barry