Having Fun with the Date Function
As an interactive form of conveying information to your visitors, this add-on through PHP scripting will allow them to easily know the date. The date function can show recent blog posts and times when you’ve posted news or updates. This is convenient when you want to form an archive and a sense of timeliness when you write your blog. Here is how the date() works.
Let’s say you want to show today’s date. In PHP coding, it would look similar to this:
<?php
echo date("m / d / Y");
?>
When you view it in your browser, it would look something like this:
As you can see, you have shown the date conveniently on your website. This becomes very efficient when it comes to news websites that usually have the date found in the header. The date() function is fun to play with because you can diversify its output using different methods and combinations of dates. What if you desire to twist around your date?
In fact, in my experience in web design, I have encountered a very common problem regarding future dates. Here’s how it goes.
You see, there is a method within the date function that works exactly that way. This is known as the time stamp option. In fact, it works conveniently for inputting exact dates, like those ten days in advance. The syntax would look something like this:
<?php
$ten_days = mktime(0,0,0,date("m"),date("d")+10,date("Y"));
echo "The product promotion ends on ".date("m/d/Y", $ten_days);
?>
The input would go something like this (provided the date is June 28, 2010):
As you can see, you can easily solve the problem of the ten days repetition. A better understanding of the syntax of the timestamp can be seen here:
mktime(hour,minute,second,month,day,year,is_dst)
Just adjust the date as you see fit and in the portion of “day”, just add +10 or another increment to show the date in ten days’ time or whatever amount you wish. This method is effective for promos or other things.
As you can see, the date() function is dynamic when it comes to showing the date, you can effectively set it to the current date for your news updates, or perhaps add a twist to the promo end of it all. You may conveniently check the PHP manual on different date formats you can try out. The date() function indeed becomes an interesting PHP function for anyone’s desire–perfect for situations such as news updates of any kind or your simple notices that you wish to make evident.
