PDA

View Full Version : vbdate() function


veenuisthebest
08-14-2008, 03:02 AM
I am not able to retrieve the current time according to user's timezone settings using vbdate()

I am using this, but this always shows 01st of January, 1970:-

$timestamp = vbdate("jS \of F, Y h:i:s A", $result['TIMESTAMP']);

Then I use this, and it works fine but always show time 5 hours back.

$eventdate = strtotime($result['TIMESTAMP']);
$timestamp = vbdate("jS \of F, Y h:i:s A", $eventdate);

What wrong am I doing? To insert current time, i have simply created a column of datatype TIMESTAMP and it inserts fine.

Thank You

MoT3rror
08-14-2008, 04:43 AM
vbdate function takes UNIX time not in a format such as YYYY-MM-DD HH:MM:SS which is returned by mysql when a column is in date format.

veenuisthebest
08-14-2008, 10:04 AM
so how to solve the problem ? please explain programmatically. How to insert current date/time so that vbdate() works.

Marco van Herwaarden
08-14-2008, 10:21 AM
Make the database column an integer(11), use TIMENOW as current value to insert and use vbdate() to make it a displayable date in the users TZ.

veenuisthebest
08-15-2008, 12:29 PM
Thank you, it works great now.

Is there a way to do just the vice versa of it ? Now I want to convert the displayed form into unix timestamp format and insert it, how should I do it ??

This is the process what I want to do:-

1. Insert date in unix format.
2. Retrieve it in desired format with vbdate().
3. Edit the retrieved date.
4. On submit, convert it in unix timestamp and insert it.

Need help with steps 3 and 4.

Thank You

Marco van Herwaarden
08-16-2008, 10:18 AM
You can use the mktime() function or better the vbmktime() wrapper.