Jump to content

date help


Recommended Posts

Hello,

        I am having a table with a timestamp field.

id::  inserteddate

1 :: 2007-01-19 21:22:23  11 weeks

2 :: 2007-01-23 21:22:23  10 weeks

3 :: 2007-01-29 21:22:23  9 weeks

4 :: 2007-02-19 21:22:23  7 weeks

5 :: 2007-02-26 21:22:23  6 weeks

6 :: 2007-03-03 21:22:23  5 weeks

7 :: 2007-03-19 21:22:23  3 weeks

 

if i want to select rows started before 6 weeks...

then the result should be

5 :: 2007-02-26 21:22:23  6 weeks

6 :: 2007-03-03 21:22:23  5 weeks

7 :: 2007-03-19 21:22:23  3 weeks

 

if i want to select rows started before 9 weeks then

result should be

3 :: 2007-01-29 21:22:23  9 weeks

4 :: 2007-02-19 21:22:23  7 weeks

5 :: 2007-02-26 21:22:23  6 weeks

6 :: 2007-03-03 21:22:23  5 weeks

7 :: 2007-03-19 21:22:23  3 weeks

 

any help?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/45377-date-help/
Share on other sites

It's not perfect, but here is the bulk of what you want to do.

 

 

<?php
$weeks=6; // set your weeks here or create your own

$d= 7 * $weeks ; // take the number of weeks you want and multiply by 7 to get total days

$weeks_ago=mktime(0, 0, 0, date("m"), (date("d")-$d),   date("Y")); //create unix time string based on a date in the past

$match_string= date("Y-m-d h:i:s",$weeks_ago); // format the date to compare to

$query="SELECT * FROM -table- WHERE inserteddate <= '$match_string' "; // we select everything that is less than or equal to our match string.
?>

Link to comment
https://forums.phpfreaks.com/topic/45377-date-help/#findComment-220336
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.