shane85 Posted April 5, 2010 Share Posted April 5, 2010 hey guys...I made a post on this few days ago but still am unsure on how I should do this, or for that matter what would be the best way. open to suggestions. what im doing is basically I have a form that submits to a database. One of the fields in my form is "contact_next", which is a drop down menu to chose from. The options are 1 day, 2 day, 3 day, 1 wk, 2 wk, 3 wk, 1 month, 2 month, 3 month, 6 month I also have it storing a timestamp of when this entry is added. So I have a time stamp of when added, and when to contact next. So id imagine I would do a time - contact_next? Or something like that - because I have an option when viewing my entrys "View by when to Contact Next" say I have 4 records that are suppost to be viewed in 1 day, so for 1 day those records will be displayed first before the records from 2 days, 3 days etc. Im not sure how to store the "contact_next" in the database to do it properly to fetch the information. thanks Link to comment https://forums.phpfreaks.com/topic/197659-date-helpcountdown-to-expiary/ Share on other sites More sharing options...
taquitosensei Posted April 5, 2010 Share Posted April 5, 2010 I would store it as a datetime then in php you can do the math to get how many days. $today="2010-04-05"; $time_next="2010-04-28"; $timediff=(strtotime($time_next)-strtotime($today)); $minutes=$timediff/60; $hours=$minutes/60; $days=ceil($hours/24); Link to comment https://forums.phpfreaks.com/topic/197659-date-helpcountdown-to-expiary/#findComment-1037398 Share on other sites More sharing options...
shane85 Posted April 5, 2010 Author Share Posted April 5, 2010 hmm I tried your code and tried to echo days and it displayed 23, which is correct and what I want. However when I entered my variables it displayed a wierd number...my code is as follows <?php $today=$arrEntry['tstamp']; $time_next=$arrEntry['contact_next']; $timediff=(strtotime($time_next)-strtotime($today)); $minutes=$timediff/60; $hours=$minutes/60; $days=ceil($hours/24); echo $days; ?> it displayed 14888 as the number of days...in my db, tstamp is 2010-04-05 15:37:54 and contact_next is 2010-10-05 does it matter that in my db for tstamp time is recorded as well? or its only looking at the date? Link to comment https://forums.phpfreaks.com/topic/197659-date-helpcountdown-to-expiary/#findComment-1037468 Share on other sites More sharing options...
taquitosensei Posted April 6, 2010 Share Posted April 6, 2010 it looks like you're data is already a timestamp so you can lose the strtotime's Link to comment https://forums.phpfreaks.com/topic/197659-date-helpcountdown-to-expiary/#findComment-1037517 Share on other sites More sharing options...
shane85 Posted April 6, 2010 Author Share Posted April 6, 2010 now it displays -14704 <?php $today=$arrEntry['tstamp']; $time_next=$arrEntry['contact_next']; $timediff=(($time_next)-($today)); $minutes=$timediff/60; $hours=$minutes/60; $days=ceil($hours/24); echo $days; ?> Link to comment https://forums.phpfreaks.com/topic/197659-date-helpcountdown-to-expiary/#findComment-1037603 Share on other sites More sharing options...
taquitosensei Posted April 6, 2010 Share Posted April 6, 2010 echo out tstamp and concat_next make sure they're both timestamps. If one is a datetime then use the strtotime on that one. Link to comment https://forums.phpfreaks.com/topic/197659-date-helpcountdown-to-expiary/#findComment-1037722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.