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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.