-1

In my mysql database table i have two columns called "date" and "time". "date" datatype is set to DATETIME and "time" datatype is set to TIMESTAMP. what i want to do is store only date in "date" column and store only time in "time" column. my table name is "loans".I'm not good in SQL querying. someone please show me exactly how to do that.

And also i have some another problems with time zones. i want to convert my database time format to UTC -5:00 (us time).how can i do that without change my PC time ?

rafalefighter
  • 714
  • 2
  • 11
  • 39

1 Answers1

0

Separating DATE and TIME for same event is a bad idea. I would go for storing it in simple DATETIME field.

But you can do it with this

Give date field type DATE(not DATETIME) and time field type TIME (yes it exists and not TIMESTAMP)

Now this will allow you to store date in YYYY-MM-DD and time in HH:MM:SS

To set the time zone of your MYSQL server you can use this one

How do I set the time zone of MySQL?

Community
  • 1
  • 1
Sushant
  • 1,354
  • 1
  • 14
  • 31
  • Thank you for your reply. can you please shoe me what are the values to type Default field. I'm updating it using alter table option not query. can i put YYYY-MM-DD and HH:MM:SS to default filed ? – rafalefighter Sep 10 '14 at 17:44
  • it giving me the same error all the time ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'HH:MM:SS AFTER `lid`' at line 2 SQL Statement: ALTER TABLE `waquis`.`loans` ADD COLUMN `time` TIME NULL DEFAULT HH:MM:SS AFTER `lid` – rafalefighter Sep 10 '14 at 17:45