日期格式的余量(dd/MM/yyyy) [英] Requrement for Date Format (dd/MM/yyyy)

查看:77
本文介绍了日期格式的余量(dd/MM/yyyy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
答:我使用的是日期格式(dd/MM/yyyy),所以以字符串格式存储在数据库中.由于数据库的日期格式为(MM/dd/yyyy),我可以更改为(dd/MM/yyyy).
B.我在SQL查询中使用GetDate(),它需要DateTime格式,所以如何将它用于数据库中存储的Date的字符串格式.

代码是:在此代码中FM_BankAC_Entry.Date是DateTime格式.我需要类似的字符串格式查询.

Hi !
A.I am using Date Format (dd/MM/yyyy) so store in DataBase in String Format.Because DateFormat of Database is (MM/dd/yyyy),can I change into (dd/MM/yyyy).
B.I am using GetDate() in SQL query, it require DateTime format.So how can I use it for string format of Date stored in Database.

Code is : In this Code FM_BankAC_Entry.Date is DateTime Format.I Require similar quiry for String Format.

SELECT     dbo.FM_BankAC_Entry.TransCode,dbo.FM_BankAC_Entry.TDate, dbo.FM_BankAC_Entry.TDetails, dbo.FM_BankAC_Entry.ChequeNo, dbo.FM_BankAC_Entry.AmtWithdr,FM_BankAC_Entry.AmtDep

FROM  FM_BankAC_Entry
where  FM_BankAC_Entry.Date between GETDATE()- @date1 and GETDATE()- @date2
        order by FM_BankAC_Entry.Date desc

推荐答案

首先,这不是一个SQL论坛,您应该将其移至适当的位置.获得更多答案和更快响应的地方.

对于任何sql date函数,日期都必须采用正确的格式(MM/dd/yyyy)格式.如果要进行日期时间比较,则不应以字符串格式在sql中存储日期.尽管通过类型转换可以将字符串值转换为日期时间,但是此处的日期格式错误.但是,您可以使用以下表达式:

SELECT CONVERT(datetime,@ date1,103)
First of all this is not a SQL forum and you should move this to the proper place for more answers and faster responses.

For any sql date functions, the date has to be in the proper format (MM/dd/yyyy) format. You should not store the date in string format in sql if you want to do date time comparison. Though by type casting you can convert a string value into a datetime one but here the date format is wrong. However, you can use the following expression:

SELECT CONVERT(datetime, @date1 , 103)


您是什么意思?
如果您的字段为DateTime格式,则数据库不会以格式存储它.只是个约会而已.仅根据您的区域设置显示.

但是,如果要将日期转换为任何Varchar格式,请在SQL Server中尝试Convert.或查看VB中的System.Globalization.CultureInfo.
What do you mean?
If your field is in DateTime format then database does not store it in format. It just a date. It only shows depending on your regional setting.

But if you want to convert the date into any Varchar format then try Convert in SQL server. or take a look at System.Globalization.CultureInfo in VB.


谢谢

我有这个问题的提示.
Thanks

I got the Tips for this Question.


这篇关于日期格式的余量(dd/MM/yyyy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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