How to convert string to DATE in PHP ? format Y-m-d Input from Textfield 2009-11-16 Thank You
<?php $input = $_POST['somewhere']; $date = date('Y-m-d', strtotime($input)); ...
Why it shows 1970-01-01 date in MySQL ?
input 2009-11-16
php+mysql สามารถเอา string ที่อยู่ในรูปformat Y-m-d ลงได้ทันทีนิครับ
Can you give some example ... in that case i got 0000-00-00
หาก mysql ของคุณสามารถเก็บ 0000-00-00 ได้(หากไม่ได้ต้องแก้ที่ my.ini)
[code] $input = "0000-00-00"; // Y-m-d $sql="INSERT INTO x (x.date) VALUES ('{$input}')" [/code]
x
x.date
you can use this example
print date('Y-m-d',strtotime('now')); print date('Y-m-d',strtotime('yesterday')); print date('Y-m-d',strtotime('+2 weeks'));
date('Y-m-d',strtotime('yesterday')); RESULT on MySQL is 2009-11-15 .... NO problem
$input = "2009-11-16"; // Y-m-d $phpdate = date('Y-m-d',strtotime('$input'));
RESULT on MySQL is 1970-01-01 ????? what happened ?????
what's your SQL query and the field type?
iPAtS
delete single quote at '$input' $phpdate = date('Y-m-d',strtotime($input));
problem solved !!! so easy ! I didn't see it , Thank you!
<?php
$input = $_POST['somewhere'];
$date = date('Y-m-d', strtotime($input));
...
Why it shows 1970-01-01 date in MySQL ?
input 2009-11-16
php+mysql สามารถเอา string ที่อยู่ในรูปformat Y-m-d ลงได้ทันทีนิครับ
Can you give some example ...
in that case i got 0000-00-00
หาก mysql ของคุณสามารถเก็บ 0000-00-00 ได้(หากไม่ได้ต้องแก้ที่ my.ini)
[code]
$input = "0000-00-00"; // Y-m-d
$sql="INSERT INTO
x
(x.date
) VALUES ('{$input}')"[/code]
you can use this example
print date('Y-m-d',strtotime('now'));
print date('Y-m-d',strtotime('yesterday'));
print date('Y-m-d',strtotime('+2 weeks'));
date('Y-m-d',strtotime('yesterday'));
RESULT on MySQL is 2009-11-15 .... NO problem
$input = "2009-11-16"; // Y-m-d
$phpdate = date('Y-m-d',strtotime('$input'));
RESULT on MySQL is 1970-01-01 ????? what happened ?????
what's your SQL query and the field type?
iPAtS
delete single quote at '$input'
$phpdate = date('Y-m-d',strtotime($input));
problem solved !!! so easy ! I didn't see it , Thank you!