如何在sqlserver中显示当前日期记录? [英] how to display current date records in sqlserver ?

查看:98
本文介绍了如何在sqlserver中显示当前日期记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



如何在sqlserver中显示当前日期记录?



我有5个sqlserver表中的列为

用户名,密码,名字,姓氏,EntryDate



我想根据今天的日期显示所有列记录。



我想根据今天的日期检索数据。



请帮助我



谢谢...

Dear All,

how to display current date records in sqlserver ?

I have 5 columns in sqlserver table as
username,password,firstname,lastname,EntryDate

I want to display all columns records based on todays date.

I want to retrieve data based on todays date.

Please can you help me

Thanks...

推荐答案

不要将日期存储为字符串:不仅效率极低;当您尝试将它们与其他日期值进行比较时,它不仅会导致大量问题;它也很容易失败。

为什么?因为如果您有两台PC输入数据,那么您的数据库几乎肯定会受到PC配置的支配!如果您有一台PC输入设置为欧洲格式且一台设置为美国的数据,则日期字符串数据不可信:2012年2月6日06-02-12,或2012年6月6日,或12月12日2006年2月,或者......



你得到了这张照片吗?更改您的数据库。将日期存储为Date或DateTime列,并将其作为参数化查询从软件中传递出来。然后你可以使用正确的SQL:

Don't store dates as strings: not only is it extremely inefficient; not only does it cause massive problems when you try to compare them with other date values; it is also very prone to failure.
Why? Because if you have two PCs entering data, then your database will almost certainly be at the mercy of the PC configuration! If you have one PC entering data that is set to European format and one set to USA, then date string data cannot be trusted: is 06-02-12 the sixth of Feb 2012, or the second of June 2012, or the twelfth of Feb 2006, or...

You get the picture? Change your database. Store dates as Date or DateTime columns, and pass them through from your software as parameterised queries. Then you can use "proper" SQL:
SELECT * FROM MyTable where DATEDIFF(d, EntryDate, GETDATE()) = 0

返回今天的所有记录。


这篇关于如何在sqlserver中显示当前日期记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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