Tags:

How to convert string to DATE in PHP ?
format Y-m-d
Input from Textfield 2009-11-16
Thank You

Get latest news from Blognone
By: aimakung
AndroidUbuntuWindowsIn Love
on 16 November 2009 - 10:28 #137697

<?php
$input = $_POST['somewhere'];
$date = date('Y-m-d', strtotime($input));
...

By: btssky
ContributoriPhoneAndroidRed Hat
on 16 November 2009 - 11:08 #137705

Why it shows 1970-01-01 date in MySQL ?

input 2009-11-16

By: Kiss on 16 November 2009 - 11:21 #137713

php+mysql สามารถเอา string ที่อยู่ในรูปformat Y-m-d ลงได้ทันทีนิครับ

By: btssky
ContributoriPhoneAndroidRed Hat
on 16 November 2009 - 12:06 #137727 Reply to:137713

Can you give some example ...
in that case i got 0000-00-00

By: Kiss on 16 November 2009 - 13:05 #137734 Reply to:137727

หาก mysql ของคุณสามารถเก็บ 0000-00-00 ได้(หากไม่ได้ต้องแก้ที่ my.ini)

[code]
$input = "0000-00-00"; // Y-m-d
$sql="INSERT INTO x (x.date) VALUES ('{$input}')"
[/code]

By: risc on 16 November 2009 - 13:03 #137733

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'));

By: btssky
ContributoriPhoneAndroidRed Hat
on 16 November 2009 - 13:19 #137739 Reply to:137733

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 ?????

By: ipats
ContributorNOOBIn Love
on 16 November 2009 - 13:42 #137745 Reply to:137739

what's your SQL query and the field type?


iPAtS

By: supersuphot
iPhoneAndroidWindows
on 16 November 2009 - 14:15 #137752 Reply to:137739

delete single quote at '$input'
$phpdate = date('Y-m-d',strtotime($input));

By: btssky
ContributoriPhoneAndroidRed Hat
on 16 November 2009 - 14:20 #137753 Reply to:137752

problem solved !!! so easy ! I didn't see it , Thank you!