richiec Posted January 29, 2008 Share Posted January 29, 2008 I think i have figured where my problem is however im not sure how to solve it.. This is what i have... <?php putenv("TZ=America/New_York"); $currentdate = date('n-j-Y'); $date = mysql_result($result,$i,"date"); $time =mysql_result($result,$i,"time"); case ($currentdate > $date): // this is where the problem is which i need help with.... echo "if $currentdate and time is > than $date $time"; break; case ($currentdate == $date): echo "if $currentdate is = to $date"; break; default: echo "defult for if $currentdate hasnt come around yet"; } ?> ok any ideas how i can get this working because it is really starting to stress me out now.... i basicly have a time stamp and date stamp in DB and all i want to be able to do is... if it is todays date but before the time it echos something... if it is past the date and time it echos something else and if it is before the date it echos something else... Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/ Share on other sites More sharing options...
phorcon3 Posted January 29, 2008 Share Posted January 29, 2008 <?php putenv("TZ=America/New_York"); $currentdate = date('n-j-Y'); $date = mysql_result($result,$i,"date"); $time =mysql_result($result,$i,"time"); if($currentdate > $date){ echo "if $currentdate and time is > than $date $time"; } elseif($currentdate == $date){ echo "if $currentdate is = to $date"; } else{ echo "defult for if $currentdate hasnt come around yet"; } ?> would that work..? Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-452891 Share on other sites More sharing options...
richiec Posted January 29, 2008 Author Share Posted January 29, 2008 no, thats how i had it set up at first. The case command is pretty much the same as else/if in this case anyway What i need it to do is read the current date and time for the time zone selected if that is > than $date $time then it echos that bit Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-452937 Share on other sites More sharing options...
richiec Posted January 30, 2008 Author Share Posted January 30, 2008 bumping... So noone knows how to read if current date and time is > than $date $time in my db? Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453397 Share on other sites More sharing options...
revraz Posted January 30, 2008 Share Posted January 30, 2008 This is your problem $currentdate = date('n-j-Y'); compare based on YYYY MM DD or by Unix Timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453399 Share on other sites More sharing options...
richiec Posted January 30, 2008 Author Share Posted January 30, 2008 ok ill start at the start.. maybe it will help you understand what i am trying to do more.. <?php putenv("TZ=America/New_York"); if(strtotime('now') > strtotime("{$date}")) {// compares current unix timestamp to that date echo "if the date and time are > than $date in db"; } else { echo "if the current date is < $date in db"; ?> That is what i had at first, and it worked fine for a few months but now i want to change it around a bit.. I want to change the date format to check a different way because year-month-day is backwards lol so i wanted to change it to check against month-day-year that is where i started using date() to put it to the format i wanted.. Other than changing the date format i wanted to add another option because the code above would display on the correct date but things change during the day.. So what i want to be able to do is: 1) have it check if current date is < than the date in DB - that displays something 2) have it check if current date is > than the date in DB but < the time in DB - that displays something else 3) have it check if current date and time is > than the date and time in DB - that displays something else so any ideas how i can set that up, and keep the date format that i want so it doesnt check year- month - day Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453425 Share on other sites More sharing options...
revraz Posted January 30, 2008 Share Posted January 30, 2008 Don't confuse date display format with storing dates and comparing them It's very easy to display the date in any format you like using the DATE function. So use either mysql date or unix date to do the actual storing and comparing, then display it any way you want. Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453474 Share on other sites More sharing options...
richiec Posted January 30, 2008 Author Share Posted January 30, 2008 i have given up on it and just changed it back to the way i have been using it.. showing one thing when it is after a date and time showing another thing when it is before date and time. i removed if it was the correct date but before the time part and gone back to using unix time to check the date and time. thanks anyway ~Rich Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453629 Share on other sites More sharing options...
revraz Posted January 30, 2008 Share Posted January 30, 2008 Not sure why that's a problem? It's easy to check dates and time in Unix format and then display them in a normal format, so I guess I'm not sure why that is a bad thing. gone back to using unix time to check the date and time. thanks anyway ~Rich Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453656 Share on other sites More sharing options...
richiec Posted January 30, 2008 Author Share Posted January 30, 2008 the thing is, i have an update page where users can update when things are due so they go there and put in a date and time for a list of things.. that date and time gets put into the DB.. the main reason i wanted to change the date format is because they didnt like the way they had to put in the date as in year-month-day so i changed the way for them to put in the date and started using date() to check against the date in the db.. i guess current date and time stamps just confuse me... Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453690 Share on other sites More sharing options...
revraz Posted January 30, 2008 Share Posted January 30, 2008 You can take the input anyway you like and convert it to store it. I allow them to enter in mm/dd/yyyy 00:00 format then I just convert that to Unix time and store it. Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453696 Share on other sites More sharing options...
richiec Posted January 30, 2008 Author Share Posted January 30, 2008 ok i decided not to give up on it how do you convert it before inserting it and then get it to display the way i want it when it gets it from db? this is what i have now.... <?php if(strtotime('now') > strtotime("{$date} {$time}")) { echo "something if current date and time is > than both $date and $time"; } elseif(((strtotime('now') > strtotime("{$date}")) & ((strtotime('now') < strtotime("{$time}"))) { echo "something if current date > $date but time is < than $time"; } else { echo "something if current date < $date"; } ?> Can you see whats wrong here? its giving me an unexpected T_ECHO error.. for this echo: <?php echo "something if current date > $date but time is < than $time"; <? also this part is just an idea a had duno if it will work or not <?php elseif(((strtotime('now') > strtotime("{$date}")) & ((strtotime('now') < strtotime("{$time}"))) <? Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453707 Share on other sites More sharing options...
richiec Posted January 30, 2008 Author Share Posted January 30, 2008 i got the 3 layers working using Unix date and time.. now all i need to do is convert it once they update it in month/day/year so that when its in the db it is unix format... and when it echos back on the site it is in month/day/year format but this is a different issue so i will make a new thread for it.. thanks for your help i would have given up otherwise. Rich Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453859 Share on other sites More sharing options...
revraz Posted January 30, 2008 Share Posted January 30, 2008 May be a better way, but this is what I do For the input form <td><input size="20" maxlength="16" type="text" name="rdate"> MM/DD/YYYY-hh:mm</td> For the php for that format $rdate is my variable from rdate above $rdate = preg_replace('%\D%','',$rdate); $month = substr($rdate, 0, 2); $day = substr($rdate, 2, 2); $year = substr($rdate, 4, 4); $hour = substr($rdate, 8,2); $min = substr($rdate, 10, 2); $rdate = mktime($hour, $min,0, $month, $day, $year); Quote Link to comment https://forums.phpfreaks.com/topic/88473-date-and-time/#findComment-453871 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.