Jump to content

Help with strtotime


Hobbyist_PHPer

Recommended Posts

Hi, I have this application where I am going to store the datetime's in UTC, and then when printed out they will be adjusted by the user's setting's time zone, time difference..., but I'm having an issue...

 

For some reason, this code won't work...

<? 
$timeDiff = $_SESSION['DirectExaminerCompanyTimeZone'] * 3600;
echo date('n-d-Y @ g:i a', strtotime($row['OrderTicketStatusDateTime']) $timeDiff); 
?>

The session variable in this case equals -6

 

If I code in -6 * 3600 instead of putting in the variable, it works, otherwise it just gives me an error

 

I also tried this, a bit of code I found on Stackoverflow, but no go either...

<? echo date('n-d-Y @ g:i a', strtotime($timeDiff, strtotime($row['OrderTicketStatusDateTime']))); ?>

Link to comment
Share on other sites

What would be even easier is to use date_default_timezone_set.

date_default_timezone_set("America/Whatever is for Central");
echo date("n-d-Y @ g:i a', $row['OrderTicketStatusDateTime']);

Except you need a timezone string, not a number.

 

I'm not really sure how that would work in this application since all datetime fields are stored in UTC and then need to be displayed in the user's local timezone

Link to comment
Share on other sites

You need an operator between the return value of strtotime and your offset variable. The reason it works when you manually type that out is because the negative symbol is being parsed as the operator.

 

Try this:

 

<? 
$timeDiff = $_SESSION['DirectExaminerCompanyTimeZone'] * 3600;
echo date('n-d-Y @ g:i a', strtotime($row['OrderTicketStatusDateTime']) + $timeDiff); 
?>

Link to comment
Share on other sites

You need an operator between the return value of strtotime and your offset variable. The reason it works when you manually type that out is because the negative symbol is being parsed as the operator.

 

Try this:

 

<? 
$timeDiff = $_SESSION['DirectExaminerCompanyTimeZone'] * 3600;
echo date('n-d-Y @ g:i a', strtotime($row['OrderTicketStatusDateTime']) + $timeDiff); 
?>

 

Yes, perfect, thank you very much for catching that

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.