Jump to content

Recommended Posts

I would do it like this:

 

$time = time(); //sets the current time
$seven_days = 60*60*24*7; // makes it seven days
$total = $time - $seven_days // subtracts seven days from current time

//make the query
$query = "SELECT * FROM table WHERE time > '$total'"; //selects any time that is greater than seven days before the time

 

This has not been tested but I am pretty sure it will work. There are other methods but it is late and my brain has almost shutdown lol.

Link to comment
https://forums.phpfreaks.com/topic/140740-date-question/#findComment-736739
Share on other sites

thanks guys but i have another question about date in my database it always saves as 2009-01-15 when i call this from the database it displays this too how can i get it to display 15-01-2009 ??? when i call it from the database i usually use $date= $row["date"];

Link to comment
https://forums.phpfreaks.com/topic/140740-date-question/#findComment-737107
Share on other sites

THANKS PERFECT

 

I HAVE JUST BEEN LOOKING FOR THE ANSWER TO THIS QUESTION ON THERE BUT CANT FIND IT.

 

HOW DO YOU GET A NUMBER STORED AS 1000000 to display 1,000,000 or 1,000,000.00 I TRIED PLAYING WITH FLOATS BUT IT DIDN'T WORK EASY TO GET 999.00 but any thing over that doesn't seem to work.??

Link to comment
https://forums.phpfreaks.com/topic/140740-date-question/#findComment-737611
Share on other sites

lol that would have been more interetsting.

 

shadiadiaiph I will give you an example. Say I had a table like this:

 

table - entries

field - id //int auto_increment primary key

field - date_entered //int

field - text_entered //varchar

 

I would then enter something in the database like so.

 

$time_now = time(); //makes a unix timestamp
$query = "INSERT INTO entries (date_entered,text_entered) VALUES ('$date','somevalue here')"; //inserts the timestamp in the date_entered field

 

Then when I wanted to display the time from the database I would show it like this:

 

$query = "SELECT * FROM entries";
$results = mysql_query($query);

while($row = mysql_fetch_array($results))
{
$date_entered = $row['date_entered']; //sets the date as a value
$formatted_date = date("m/d/Y", $date_entered); //formats the timestamp into 01/15/2009
echo $formatted_date; //displays the date

 

Check out this site for the date() function http://www.tizag.com/phpT/phpdate.php. You should also look into the mktime() and strtotime() functions.

Link to comment
https://forums.phpfreaks.com/topic/140740-date-question/#findComment-737984
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.