I need to format PHP to use with one of my date field (DATETIME).
I want to get current time and format it. I have checked some googled articles but I cannot get far.
Please help me!
Stefano Mtangoo
455
Senior Poster
Recommended Answers
Jump to PostIn php use:
$mydate = date('Y-m-d H:i:s'); //this will produce a date like 2009-09-20 17:44:09 $query = mysql_query("INSERT INTO mytable SET mydatefield = '{$mydate}', field2 = 'value2'");
Jump to PostDont format the date time in the database
text formatted dates are for humans to read, sql is not human does not need any of that and it makes the processing slower
sql Date, php date, unix timestamp, are all a single 10byte numeric that stores complete date and time
…
Jump to PostI'd agree with AB about now() in SQL - better than using date() first and then using it, but if you need the current date for output to screen as well as input to db, you may as well.
All 12 Replies

diafol
almostbob
866
Retired: passive income ROCKS
Will Gresham
commented:
+1
+2

diafol
Stefano Mtangoo
455
Senior Poster
hemgoyal_1990
5
Junior Poster
Stefano Mtangoo
455
Senior Poster
hemgoyal_1990
5
Junior Poster
Stefano Mtangoo
455
Senior Poster
almostbob
866
Retired: passive income ROCKS
Stefano Mtangoo
455
Senior Poster
almostbob
866
Retired: passive income ROCKS
Stefano Mtangoo
455
Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.