Can you please tell me how do I compare two dates in PHP. Is there any in -build functions ?
Also tell me how do I acces an external jpg file in a PHP source code.
Printable View
Can you please tell me how do I compare two dates in PHP. Is there any in -build functions ?
Also tell me how do I acces an external jpg file in a PHP source code.
- In PHP dates a represented using a UNIX timestamp which is an integer corresponding to the number of seconds since 1/1/1970. To compare two dates, do what you would do when comparing numbers. The higher the number the larger the date. Have a glance at PHP's date and time functions.
- You can open an external JPG as if it were a standard file on the filesystem:
The $jpg variable will now contain the binary data from the picture. If you wanted to display the picture you must then send the appropriate Content-Type header.PHP Code:$jpg = file_get_contents('http://www.example.com/picture.jpg');
PHP Code:header('Content-Type: image/jpeg');
echo($jpg);
In reply to: http://www.vbforums.com/showthread.p...98#post2574998
I already explained how to open a JPG. The file_get_contents() function is what you need, just replace the web address with the path to the file.
If you look at the date/time functions I linked to previously you'll see that you need the [http://www.php.net/strtotime]strtotime()[/url] function to convert the date string into a timestamp which you can use for comparisons.
The following constants will help:
PHP Code:define('SECONDS_MINUTE', 60);
define('SECONDS_HOUR', SECONDS_MINUTE * 60);
define('SECONDS_DAY', SECONDS_HOUR * 24);
define('SECONDS_WEEK', SECONDS_DAY * 7);
define('SECONDS_YEAR', SECONDS_DAY * 365);
$difference = $toDate - $fromDate;
// find the number of years
$years = (int) ($difference / SECONDS_YEAR);
$remain = $difference % SECONDS_YEAR;
// find the number of days - number of years
$days = (int) ($remain/ SECONDS_DAY);
$remain = $remain % SECONDS_DAY;
// find the number of hours - number of days - number of years
$hours = $remain / SECONDS_HOUR;
echo("$years years(s), $days day(s), $hours hour(s)");