Jump to content

[SOLVED] Code for making selection based on date?


R0CKY

Recommended Posts

I have a database filled with records, each one of which has a file_time field that is stored in a format like this "1101765599" - I assume that's some kind of standard time code that can be changed into a standard date.

 

What I'd like to do is have php count how many records were added in the last 7 days. Each file has a sequntial File_ID field so that could help...?

 

So to break it down, I think this would be the steps.

 

Assign the most recent File_ID to variable A

Assign the current date to variable B

Subtract seven days and assign that date to variable C

Find the first record with File_time matching variable C

Subtract the File_ID of that record from variable A - and that would be the count.

 

I think that's the best logic, but I would need pointers with the php.... anyone start me off please?

 

 

Link to comment
Share on other sites

the number you mentioned is a <i>timestamp</i> and equates to 29th November 2004 if you want to know all entries in the last 7 days you need the <i>timestamp</i> for 7 days ago

<?php
$today = strtotime("NOW"); // timestamp for today
$lastweek = strtotime("-7 day", $today); //take off seven days
$query = "SELECT * WHERE File_time > '$lastweek'";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.