Skip to main content
Inspiring
August 26, 2008
Question

php input date/time as timestamp with timezone

  • August 26, 2008
  • 2 replies
  • 746 views
This is a nightmare!!!!

I have numerous databases, all of which use timestamp format date/times, which are easy to echo according to user timezone preferences using putenv ("TZ=".$_SESSION['MM_UTZ']); and echo date($_SESSION['MM_UTF'], ($whatever));

The only problem is, I have only used these for stamping "date created" or "date edited" values using Time()

What I am trying to achieve is:

User 1 in UK enters date and time, using a javascript datetime picker (which normally enters data into field in Y-m-d H:i:s) and the php inserts this in timestamp format according to timezone.

User 2 in US looks at date and time and this is echo'd according to his timezone.

Sounds simple...

I have managed to get so far with the new DateTime object which incorporates the user timezone preference ($utz)

$ndttime= new DateTime($timefield, new DateTimeZone($utz));

I can then echo this effectively using

echo $ndttime->format('$utf'); ($utf being user timeformat preference)

My stupid problem is trying to get the $ndtime into the database!!!!

I know this sounds ridiculous but I use the DW insert wizard which only uses values from a form and if I echo $ndtime into a hidden field, it doesn't process this value in time.

I attach the current insert script.

Is this simple?


Heeeeelp.
This topic has been closed for replies.

2 replies

Inspiring
August 27, 2008
I have a temporary test page with all the various functions.

http://www.freecrm.x10hosting.com/timetest.php
Participant
August 27, 2008
how does this format when you echo to the page

echo $ndttime->format('$utf');
Inspiring
August 27, 2008
quote:

Originally posted by: AXEmonster
how does this format when you echo to the page

echo $ndttime->format('$utf');


This will echo as a date/time object - i.e. Y-m-d H:i:s, but the $utf variable is a session variable with user time format preferences, so it could be D, d/m/Y H:i:s or m-d-Y H:i:s etc.