0

I'm using jQuery Ajax to store some value in MySql DB

So far I'm passing a start_time as a datetime object like

Wed Aug 15 2012 14:00:00 GMT+0530 (IST)

and I'm getting this value on my php page like

1345019400

in my db, I want to store that value like

2012-8-17 20:45

so the $_POST['start_time'] that value is looking like an integer(I'm not sure )

my question is what to do with that integer value so that it could store in my db like

2012-8-17 20:45
2

6 Answers 6

0
$bla=1345019400;

$date=date('Y-m-d H:i',$bla);
echo $date;
Sign up to request clarification or add additional context in comments.

Comments

0

The "integer" is a timestamp! Format it using the PHP DateTime::format function

Comments

0

You get timestamp so you have to transform it using date function:

<?php
    $date = date('YYYY-mm-dd hh:ii', $_POST['start_time']);
?>

Comments

0

It's a timestamp. Have a look at the PHP date function to format it.

Comments

0

your php needs to format it into mysql date format before it inserts (assuming the data type on your column is DATETIME)

Check out the way php works with dates.

Also if you are having trouble with the date converting, convert it all to an Epoch string between javascript and php, then convert it just before insertion.

Let me know if that makes sense.

2 Comments

No worries (+1) me if you want :P
P.S the DATETIME format for mysql is: "YYYY-mm-DD hh:MM:ss" so use that in your php functions.
0
date("M-d-Y g:i", $date);

read documentation for function date()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.