Page 1 of 1

timestamp comparison

Posted: Wed Aug 27, 2008 6:42 am
by geethalakshmi
Hi,

In my download manager script I want to increment the download count when ever user downloads the script and also i want to check whether the user download the script more than once within that day, For this i want to compare the current timestamp with the timestamp period for that day. Please help me how to do this comparison.

Thanks in advance
Geetha

Re: timestamp comparison

Posted: Wed Aug 27, 2008 7:49 am
by jayshields
Incrementing a download count is trivial, so I won't go into that.

Your second question, do you mean within the last 24 hours or actually on the same day (date)? You could do this in SQL or PHP quite easily, possibly using INTERVAL for the former and mktime() for the latter.

Re: timestamp comparison

Posted: Wed Aug 27, 2008 8:32 am
by marcth

Code: Select all

$dateParts = date_parse('2008-08-27');
$timestamp = mktime($dateParts ['hour'], $dateParts ['minute'], $dateParts ['second'], $dateParts ['month'], $dateParts ['day'], $dateParts ['year']);
 
if($timestamp > mktime()) {
  print 'The date is in the future';
elseif($timestamp < mktime()) {
  print 'The date is in the past';
}