如何检索与今天日期相关的arecord,即8月5日 [英] how to retrieve arecord related to todays date ie august 5

查看:66
本文介绍了如何检索与今天日期相关的arecord,即8月5日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做图像幻灯片放映这些图像幻灯片与sqlserver中与sys日期相关的图像,我已经输入当前日期列值为august5但我的系统日期是05-08-2015所以明天我的图像应该与8月6一起滑动但我的系统日期06-08-2015

所以任何身体都给出了想法或给我任何例子

i am doing image slide show these images slide with images in sqlserver related to sys date and i have entered current date column values as august5 but my sys date is 05-08-2015 so for tomorrow my images should slide with august 6 but my sys date 06-08-2015
so any body giveme idea or give me any examples

推荐答案

检索数据时从SQL Server,您始终可以通过实现自己的逻辑来创建所需的格式。只需要在SELECT语句中进行更改。 DATENAME() DATEPART() 功能可用于实现此目的。

检查 -

While retrieving data from SQL Server, you can always create the format as required by implementing your own logic. Only you need to make changes in the SELECT statement. DATENAME() and DATEPART() function can be used to achieve this.
Check this-

SELECT DATENAME(MONTH,GETDATE())+' '+CAST(DATEPART(DAY,GETDATE()) AS VARCHAR)



输出:


OUTPUT:

Result
--------
August 5





如果你希望月份名称为小写,然后使用 LOWER() 功能如下 -



If you want the month name to be in lower case then use LOWER() function as follows-

SELECT LOWER(DATENAME(MONTH,GETDATE()))+' '+CAST(DATEPART(DAY,GETDATE()) AS VARCHAR) AS Result



输出:


OUTPUT:

Result
--------
august 5

希望,它会有所帮助:)

Hope, it helps :)


请阅读我对该问题的评论。

Please, read my comment to the question.

使用正确的数据类型非常重要。 日期是日期,而不是字符串! 换句话说:为什么要使用转换,何时可以使用适当的过滤数据数据类型?

It's very important to use proper data type. Date is a date, not string! In other words: Why to use conversion, when you can filter data using proper data type?

SELECT <Field_list>
FROM YourTableName
WHERE Month(DateField) = Month(GETDATE()) AND Day(DateField) = Day(GETDATE())





这个是忽略一年的部分日期的方法。



更多:

MONTH(Transact-SQL) [ ^ ]

DAY(Transact-SQL) [ ^ ]

GETDATE(Transact-SQL) [ ^ ]



This is the way to ignore a year part of date.

More:
MONTH (Transact-SQL)[^]
DAY (Transact-SQL)[^]
GETDATE (Transact-SQL)[^]

这篇关于如何检索与今天日期相关的arecord,即8月5日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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