Home  |  About  | Last |  Submit  |  Contact
AllQuests.com

Previous Question:  Each page view image set is refreshed  phpBB 3.0.x 3.0.x Support ForumNext Question:  F S Blackberry curve 8300  Marketplace Archive
Question Date Previous Day ( SitePoint Forums PHP )
Updated: 2008-11-23 06:55:02 (5)
Date Previous Day

Hi guys,

How do I insert into a database table the previous day's date?

e.g. Today is Thursday the 25th but I want Wednesday's date to be inserted.
How is this done?

PHP Code:

  $query = "INSERT INTO $table (name, size, type, content, file_date) ".
                
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', NOW())";
Database date field: file_date(date)

Answers: Date Previous Day ( SitePoint Forums PHP )
Date Previous Day

Might want to have a look at http://www.php.net/strtotime. And play a little with the possibilities

timvw

Date Previous Day

This worked.
PHP Code:

$query="INSERT INTO test values(NULL, 'test', DATE_SUB(NOW(), INTERVAL 1 DAY))"; 

Now how can I check if today is a Monday so that the date can be inserted as the previous Friday? i.e. need to leave out the weekends.

Is this possible?

Thanks.

Kevin.

obrienkev

Date Previous Day

You could also use MySQL, eg
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', NOW() - INTERVAL 1 DAY)";

markl999

Date Previous Day

Using multiple functions together. It's actually safer to use mktime than time() when creating a UNIX time for past/future dates. You could also use strtotime() if you wanted...depending on the purpose.

I'd use mktime though. There are examples directly in the PHP manual/documentation if you look up the mktime function, so I won't list it here.

malikyte

Date Previous Day

You could just get the current date/time and minus 24 hours, then enter the new variable in the DB... for example...

PHP Code:

/// 1 hour in unix time ///

$minusHour = time() - (1 * 60 * 60);

/// get date and time -1 hour ///
$yesterdaysDate = date('d-m-Y H:i:s', $minusHour);

philm

Previous Question:  Each page view image set is refreshed  phpBB  phpBB 3.0.x 3.0.x Support ForumNext Question:  F S Blackberry curve 8300  Mac Forums  Marketplace Archive

- Source: Date Previous Day SitePoint Forums PHP
- Previous Question: Each page view image set is refreshed phpBB phpBB 3.0.x 3.0.x Support Forum
- Next Question: F S Blackberry curve 8300 Mac Forums Marketplace Archive





AllQuests.com