简体   繁体   English

可能是正确的保存日期作为sql中的varchar吗?

[英]May be correct save date as varchar in sql?

I usually keep the date as timestamp in sql. 我通常将日期保留为sql中的时间戳。

But now Im doing a project that I want that the date appears like "Wednesday, 30 April, 2014". 但是,现在我正在做一个项目,希望日期显示为“ 2014年4月30日,星期三”。

And Im using datepicker to format the date like I want and its working fine. 我使用datepicker格式化日期,就像我想要的那样,它的工作正常。

$('.datepicker').datepicker({
    dateFormat: 'DD, d MM, yy',         
});

But now I am in doubt, if it is appropriate to save date as varchar, but also dont seems possible to save "Wednesday, 30 April, 2014" as timestamp or datetime or someting else date option. 但是,现在我不确定是否将日期另存为varchar,但似乎也无法将“ 2014年4月30日,星期三”另存为时间戳或日期时间或其他日期选项。

What do you think its better? 您认为哪个更好?

Use DateTime or TimeStamp but do not use a VarChar . 使用DateTimeTimeStamp ,但使用VarChar

What do you think its better? 您认为哪个更好?

This type of question are problematic on StackOverflow, but it has been asked before . 这种问题在StackOverflow上是有问题的,但是之前已经有人提出过

If you ever store it as a VARCHAR it will make your life very hard. 如果您将其存储为VARCHAR,将使您的生活非常艰难。 Because doing calculation on dates will just be a real hassle. 因为对日期进行计算将是一个真正的麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM