Jump to content

date and time


richiec

Recommended Posts

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...

Link to comment
Share on other sites

<?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..?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

ok i decided not to give up on it :P 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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.