SQL Server中的日期部分功能 [英] date part function in sql server
本文介绍了SQL Server中的日期部分功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在sql server的表中有一个列为GDate,并通过getdate()函数在其中插入了日期,并获取了小时,分钟,秒的日期为
Hi All,
I have a column as GDate in a table in sql server and inserted date in that by getdate()function and fetching hours,minutes,sec of date as
select datepart(d,GDate),datepart(hour,GDate),
datepart(minute,GDate),datepart(second,GDate) from tablename
现在我要检查日期是上午还是下午.
datepart()是否有任何功能只能检查AM或PM.
请让我知道.
谢谢你
穆罕默德. wasif
Now I want to check that date was in AM or PM .
Is there any function with datepart() to check only AM or PM.
Please Let me know .
Thanking You
Mohammad. wasif
推荐答案
^ ]应该可以帮助您.
This link [^]should help you out.
检查以下链接是否有解决方法,
http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions
谢谢,
www.codecollege.net | www.InterviewsGuru.com | www.chitraguptan.com | www.thekumbakonam.com
check the following link it has the solution,
http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions
Thanks,
www.codecollege.net | www.InterviewsGuru.com | www.chitraguptan.com | www.thekumbakonam.com
试试看,
Hi try this,
SELECT SUBSTRING(CONVERT(varchar(20), yourdate, 22), 18, 3) AS Expr1
FROM table
ORDER BY expr1 ;
SUBSTRING(CONVERT(varchar(20), yourdate, 22), 18, 3)-->it gives you a am/pm.
o/p:
----
am
pm
am
pm
这篇关于SQL Server中的日期部分功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文