Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Date

Posted by: tudsy Jun 26 2018, 11:07 AM

Hi

Just one question.


I am trying to put a date in a database. But I am not having much luck. I have created the date object. But what do I put in the insert query for the dt variable?


Thanks.


https://ecovib2d.com.au/ECOVIB2D/MYART/index.txt

Posted by: CharlesEF Jun 26 2018, 01:54 PM

If I understand your question correctly all you need to store is the date string, not a date object. So, if $date = "2018/06/30"; then you put $date in the query.

Posted by: tudsy Jun 26 2018, 02:20 PM

QUOTE(CharlesEF @ Jun 27 2018, 04:24 AM) *

If I understand your question correctly all you need to store is the date string, not a date object. So, if $date = "2018/06/30"; then you put $date in the query.




Hi

Thanks for that.

By putting a string constant in $date fill up that field in the database every Time?


Thanks.

Posted by: CharlesEF Jun 26 2018, 02:52 PM

Since it's been awhile since I've inserted any dates I went back and looked at some old code. I used the date and strtotime commands, like this:

CODE
$date = date(DATE_DB, strtotime($_POST['date']));
DATE_DB is the date format I want stored in the database. Of course, you want to validate any user data before you insert it.

To be honest, since the date command returns a string formatted as a date I wonder if that old code was really needed. Seems my original idea should work without any problems, $date = "2018/06/30";. Of course, you should validate the date before you try to store it, I don't think MySQL will store invalid dates.

Posted by: CharlesEF Jun 26 2018, 04:24 PM

Oh, I remember why I used that old code. The user date format is not the same as the date format I use in the database so I used that 1 line of code to convert the user date into a database date (format wise).

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)