Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-13-2008, 10:45 AM Set date for 45 days
Red_X_'s Avatar
Extreme Talker

Posts: 158
Location: Houston
Trades: 0
Essentially this is what I want to do.

Say I register today on the 13 OCT 2008. I want my php scrip to pull the date from the database. And when its been in the database for more then 45 days. I don't want it to display on the page.

Any help would be appreciated.

Thank you,

Red_X_
__________________
"Good News Everyone, by reading this your hearing my voice."
Red_X_ is offline
Reply With Quote
View Public Profile Visit Red_X_'s homepage!
 
 
Register now for full access!
Old 10-13-2008, 04:18 PM Re: Set date for 45 days
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Add the fields like 'Killonthisday' and 'active'. Use a cron (which runs daily) to change the active field to say something like 'no' on the date set in 'Killonthisday'.

Alternatively, you could make the SQL query be all like "If the date is more then 'date' don't show it", but I'm not 100% on how to do that
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 10-13-2008 at 04:20 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-13-2008, 07:19 PM Re: Set date for 45 days
Red_X_'s Avatar
Extreme Talker

Posts: 158
Location: Houston
Trades: 0
Quote:
Originally Posted by rogem002 View Post
Add the fields like 'Killonthisday' and 'active'. Use a cron (which runs daily) to change the active field to say something like 'no' on the date set in 'Killonthisday'.

Alternatively, you could make the SQL query be all like "If the date is more then 'date' don't show it", but I'm not 100% on how to do that
I would like to do it in PHP. ^^ But thanks.

All I want is to take the current day and add it up by 45 to get the next date. :S But I can't seem to figure it out. I see ones using mktime...but there must be a easier way.
__________________
"Good News Everyone, by reading this your hearing my voice."
Red_X_ is offline
Reply With Quote
View Public Profile Visit Red_X_'s homepage!
 
Old 10-14-2008, 04:05 AM Re: Set date for 45 days
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
There are various ways you could do this. Problems arise due to differing way PHP and Mysql deal with dates. Php uses the unix timestamp integer and Mysql uses a DATETIME string.

This uses Mysqls date manipulation. Add a new column/field to your register table such as 'date_insert' to your table 'tbl_name' with a TIMESTAMP datatype and with a default of current_timestamp. When a new record is inserted this value will be given the current date as a datetime string not as a UNIX timestamp.
MYSQL code
Code:
         ALTER  TABLE  `tbl_name`  ADD  `date_insert` TIMESTAMP NULL  DEFAULT CURRENT_TIMESTAMP
Then when you do your select statement
PHP Code:
$SQL ="SELECT * FROM tbl_name WHERE DATE_SUB( CURDATE( ) , INTERVAL 45 DAY ) <= 'date_insert'  "
This will select all rows that have a datetime string within past 45 days.
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 10-14-2008, 12:25 PM Re: Set date for 45 days
Red_X_'s Avatar
Extreme Talker

Posts: 158
Location: Houston
Trades: 0
Quote:
Originally Posted by maxxximus View Post
There are various ways you could do this. Problems arise due to differing way PHP and Mysql deal with dates. Php uses the unix timestamp integer and Mysql uses a DATETIME string.

This uses Mysqls date manipulation. Add a new column/field to your register table such as 'date_insert' to your table 'tbl_name' with a TIMESTAMP datatype and with a default of current_timestamp. When a new record is inserted this value will be given the current date as a datetime string not as a UNIX timestamp.
MYSQL code
Code:
         ALTER  TABLE  `tbl_name`  ADD  `date_insert` TIMESTAMP NULL  DEFAULT CURRENT_TIMESTAMP
Then when you do your select statement
PHP Code:
$SQL ="SELECT * FROM tbl_name WHERE DATE_SUB( CURDATE( ) , INTERVAL 45 DAY ) <= 'date_insert'  "
This will select all rows that have a datetime string within past 45 days.
I just made another field in the database called exdate. And figured it out, after some research.

PHP Code:
$datex date("Y-m-d"strtotime("+45 days")); 
__________________
"Good News Everyone, by reading this your hearing my voice."
Red_X_ is offline
Reply With Quote
View Public Profile Visit Red_X_'s homepage!
 
Old 10-16-2008, 08:40 PM Re: Set date for 45 days
JohnColonJr's Avatar
Novice Talker

Posts: 7
Name: John Colon Jr
Location: Boston
Trades: 0
I ran into the exact issue about a month ago, what was the final solution?
__________________
John Colon Jr
Leadsoft Consulting
Boston, MA
JohnColonJr is offline
Reply With Quote
View Public Profile
 
Old 10-16-2008, 09:46 PM Re: Set date for 45 days
Red_X_'s Avatar
Extreme Talker

Posts: 158
Location: Houston
Trades: 0
Quote:
Originally Posted by JohnColonJr View Post
I ran into the exact issue about a month ago, what was the final solution?
PHP Code:
$datex date("Y-m-d"strtotime("+45 days")); 
There you go.
__________________
"Good News Everyone, by reading this your hearing my voice."
Red_X_ is offline
Reply With Quote
View Public Profile Visit Red_X_'s homepage!
 
Reply     « Reply to Set date for 45 days
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25572 seconds with 12 queries