timestamp comparison

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
geethalakshmi
Forum Commoner
Posts: 31
Joined: Thu Apr 24, 2008 10:38 pm

timestamp comparison

Post 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
Last edited by onion2k on Wed Aug 27, 2008 6:49 am, edited 1 time in total.
Reason: Unnecessary link removed. Don't add it again or you'll be banned for spamming.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: timestamp comparison

Post 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.
marcth
Forum Contributor
Posts: 142
Joined: Mon Aug 25, 2008 8:16 am

Re: timestamp comparison

Post 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';
}
Post Reply