scott botkins Posted August 26, 2007 Share Posted August 26, 2007 I'm wanting to have a button on my website for each blog post, however if the blog post is 5 days old it will not display the button on the page. What would be the best way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/ Share on other sites More sharing options...
AndyB Posted August 26, 2007 Share Posted August 26, 2007 With conditional code that compares today's date with the date of the blog post and outputs the 'button' only for recent posts. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334734 Share on other sites More sharing options...
scott botkins Posted August 26, 2007 Author Share Posted August 26, 2007 Do you know where I could find such a code to do this? I'm not well advanced in php just yet. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334736 Share on other sites More sharing options...
matthewhaworth Posted August 26, 2007 Share Posted August 26, 2007 Something like this. <?php $day = date("d",$strtotime("+5 days",$database_timestamp); $month = date("m",$database_timestamp); $year = date("y",$database_timestamp); $expire = mktime(0,0,0,$month,$day,$year); if (time() < $expire) { // show button } ?> Compare the $expire date to the current date.. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334743 Share on other sites More sharing options...
teng84 Posted August 26, 2007 Share Posted August 26, 2007 better to use sql i guess where etc....datediff(now(),'2004-10-10') >5 Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334747 Share on other sites More sharing options...
scott botkins Posted August 26, 2007 Author Share Posted August 26, 2007 The only thing I'm able to output using my cms software is the date format Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334749 Share on other sites More sharing options...
matthewhaworth Posted August 26, 2007 Share Posted August 26, 2007 better to use sql i guess where etc....datediff(now(),'2004-10-10') >5 Lol, I'm always coming out with these elaborate ideas, then there turns out to be like.. a one line method of doing it. The only thing I'm able to output using my cms software is the date format You should be in the PHP, not the CMS ?? Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334756 Share on other sites More sharing options...
teng84 Posted August 26, 2007 Share Posted August 26, 2007 You should be in the PHP, not the CMS ?? i believe CMS is done by php here i dont get you guys???? Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334759 Share on other sites More sharing options...
scott botkins Posted August 26, 2007 Author Share Posted August 26, 2007 better to use sql i guess where etc....datediff(now(),'2004-10-10') >5 Lol, I'm always coming out with these elaborate ideas, then there turns out to be like.. a one line method of doing it. The only thing I'm able to output using my cms software is the date format You should be in the PHP, not the CMS ?? Yea I'm in php, I'm just lost on how exactly to use your code because I'm new at using this. For example my cms template variables are <Field: TwoDigitMonth>-<Field: TwoDigitDay>-<Field: TwoDigitYear> will display 08-26-07 if a post was posted today. I'm lost on where I'm suppose to put those variables I just listed in your code. Thanks for the help on this so far, appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334760 Share on other sites More sharing options...
teng84 Posted August 26, 2007 Share Posted August 26, 2007 I'm wanting to have a button on my website for each blog post, however if the blog post is 5 days old it will not display the button on the page. What would be the best way to do this? in your question you only need this and i guess its the best where etc....datediff(now(),'2004-10-10') >5 because you will only limit your output to those less than 5 days that code i gave you will limit it and you dont need to add something simply modify your query and add that Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334765 Share on other sites More sharing options...
scott botkins Posted August 26, 2007 Author Share Posted August 26, 2007 So I put <? php datediff(now(),'<Field: Year>-<Field: TwoDigitDay>-<Field: TwoDigitMonth>') >5 ?> Right? Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334792 Share on other sites More sharing options...
teng84 Posted August 26, 2007 Share Posted August 26, 2007 i dont know how your cms is designed but i believe it should be inside your select statement select * from table where datediff( now(), field) <5 Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334800 Share on other sites More sharing options...
scott botkins Posted August 26, 2007 Author Share Posted August 26, 2007 I'm not using a database, this code must be placed on a .php page. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334802 Share on other sites More sharing options...
teng84 Posted August 26, 2007 Share Posted August 26, 2007 LOL what kind of CMS is that its content management system right? i have seen and also part of some of this stuff and i believe cms means using the db on its max extent such as 98percent of your site runs using the db Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334804 Share on other sites More sharing options...
scott botkins Posted August 26, 2007 Author Share Posted August 26, 2007 This isn't exactly for blogs. This is for something else, it creates a .php page when information is submitted. What I am looking for is something when you insert the date 08-26-07 it will show something for 5 days, after 5 days that button will expire and not show anymore. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334808 Share on other sites More sharing options...
teng84 Posted August 26, 2007 Share Posted August 26, 2007 select *, datediff( now(), field) as x from table where etc.... assuming you have an array for that query or result how ever you made it if ($row['x'] <5) show what ever you want does it make sense Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334813 Share on other sites More sharing options...
scott botkins Posted August 27, 2007 Author Share Posted August 27, 2007 This script doesn't use mysql or any kind of db lol. It creates a static php page, the only way I can do this is using a timestamp of some sort. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334933 Share on other sites More sharing options...
matthewhaworth Posted August 27, 2007 Share Posted August 27, 2007 I don't see what's wrong with my code.. lol, I mean, it's slightly longer but it's a lot easier to comprehend. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334937 Share on other sites More sharing options...
scott botkins Posted August 27, 2007 Author Share Posted August 27, 2007 I don't see what's wrong with my code.. lol, I mean, it's slightly longer but it's a lot easier to comprehend. I would use your code I just don't know where to insert the date fields that I listed a few posts ago. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334940 Share on other sites More sharing options...
teng84 Posted August 27, 2007 Share Posted August 27, 2007 i guess its better to use the other person codes if that is easier for you then if it is working i suggest try the better one dude post the part of the code where you think that code should be inserted Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334944 Share on other sites More sharing options...
matthewhaworth Posted August 27, 2007 Share Posted August 27, 2007 You should be in the PHP, not the CMS ?? i believe CMS is done by php here i dont get you guys???? I don't get why he's using template variables.. think about it, it sounds like he's using a .tpl in something like phpbb.. .tpl can't process php. Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334955 Share on other sites More sharing options...
scott botkins Posted August 27, 2007 Author Share Posted August 27, 2007 Below is something I'm doing myself, it's what I'm looking for. I don't have it working yet but maybe someone can help me. <?php $date1 = mktime(0,0,0,09,01,2007) - mktime(0,0,0,09,10,2007); $date2 = "432000"; if ($date1 < $date2) { echo "Not Expired"; } else { echo "Expired"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-334991 Share on other sites More sharing options...
matthewhaworth Posted August 27, 2007 Share Posted August 27, 2007 Below is something I'm doing myself, it's what I'm looking for. I don't have it working yet but maybe someone can help me. <?php $date1 = mktime(0,0,0,09,01,2007) - mktime(0,0,0,09,10,2007); $date2 = "432000"; if ($date1 < $date2) { echo "Not Expired"; } else { echo "Expired"; } ?> That is essentially what mine did. Look: <?php // This code here is used so we can prepare for the make time function. // This date function takes the day that the blog was created on, an adds 5 days to it, moving over to the next month or even next // year if it needs. $day = date("d",$strtotime("+5 days",$database_timestamp); $month = date("m",$strtotime("+5 days",$database_timestamp)); $year = date("y",$strtotime("+5 days",$database_timestamp)); // This is the data that the button should not longer appear after $expire = mktime(0,0,0,$month,$day,$year); // This compares the current time, time(), with the expiration time and the displays the button if it hasn't expired. if (time() < $expire) { // show button } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66800-date-expiration-help/#findComment-335021 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.