Jump to content

Storing custom date into SQL table


soltek

Recommended Posts

Hey there,

 

this is a bit embarrassing, but I dont know how to store correctly, dates on a SQL table.

I've been googling it for a while and got confused.

 

So, I have a table, where the user would type a date, as 20/10/2012 23:30 inside a form field.

That form would store the date in the sql table.

Do you know any website that explains how to send the information properly?

 

Also, later I'll need to print on a page how much time lefts to that date - in this case, one year. Would a simple subtraction do?

 

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/249456-storing-custom-date-into-sql-table/
Share on other sites

First, you want a column that is made for timestamps, so you would use a data type of "datetime".

Second, you don't want to store the value like like this "20/10/2012 23:30" in the database, you would store it like this "2012-10-20 23:30:00" (YYYY-MM-DD HH:MM:SS)

 

Now MySQL can easily do date/datetime functions on your dates. What you have is a valid date format, but NOT a valid MySQL date format.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.