DATETIME数据类型 [英] DATETIME datatype

查看:122
本文介绍了DATETIME数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以dd-mm-yyyy格式保存日期,但问题是

 创建  DATELOG( DATE   DATETIME ,NAME  VARCHAR ( 20 ))
- 这是在mm-dd-yyyy格式保存中
插入  INTO  DATELOG (转换(日期时间' ' - 此格式未保存,格式为dd-mm-yyyy 
插入  INTO  DATELOG (转换(日期时间' ' 选择 *  FROM  DATELOG
选择替换(转换( VARCHAR ( 13 ), DATE  105 ),' -'' /') AS   DATE  -  ------------------------ --------------------------------------------------  



如果可能的话,请发给我Querry

事前,谢谢您,如果您希望在将数据保存到数据库时使用特定格式,则可以将数据库的语言设置更改为所需的日期格式.

只要数据类型为DateTime并且系统正在对其应用已定义的格式,就不能在插入时强制使用它.

虽然,通常这不是必需的.您的关注点应该是在检索或在表示层中显示时的数据.到时候,您可以指定一种特定的格式来显示.


不要将日期/时间保存为字符串,这只会引起问题.这就是为什么DATETIME类型存在的原因.您唯一需要任何格式(dd/mm/yy,yy/mm/dd,mm/dd/yy等)的日期都是在输出设备(屏幕,打印机等)上显示日期时.如果已将其存储为字符串,那么您将失去灵活性,无法以其他格式,时区等显示它.


i woul like to save date in dd-mm-yyyy format but problem is that

CREATE TABLE DATELOG (DATE DATETIME,NAME VARCHAR(20))
--this is in mm-dd-yyyy formate save
INSERT INTO DATELOG VALUES(CONVERT(datetime,'2/1/84'),'XXX')
--this is in dd-mm-yyyy format not save
INSERT INTO DATELOG VALUES(CONVERT(datetime,'22/1/84'),'XXX')

SELECT * FROM DATELOG
SELECT REPLACE(CONVERT(VARCHAR(13),DATE,105),'-','/') AS DATE FROM DATELOG

----------------------------------------------------------------------------



if possible then send me querry

thanx in advance

解决方案

Well, if you want a specific format while saving the data in database, then change the language setting of your DB to desired format of date.

You cannot force it while inserting as long as the datatype is DateTime and the system is applying a defined format to it.

Though, generally this is not required. Your concern should be with data while retrieving or showing in presentation layer. That time, you can specify a particular format to display.


Do not save dates/times as strings, it just causes problems; that is why the DATETIME type exists. The only time you ever need the date in any format (dd/mm/yy, yy/mm/dd, mm/dd/yy etc.) is when you display it on an output device (screen, printer etc). If it is already stored as a string then you lose all flexibility for displaying it in alternate formats, time zones etc.


这篇关于DATETIME数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆