sql 如何在SQL_vertica中提取部分日期

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 如何在SQL_vertica中提取部分日期相关的知识,希望对你有一定的参考价值。


---------------------------Vertica----------------------------------------------------------------------------
select

Now(),                                 ---find current timestamp

Date(Now()),                           ---find today's date
Year(Now()),                           ---find today's year
Quarter(Now()),                        ---find today's quarter
Month(Now()),                          ---find today's month
Day(Now()),                            ---find today's day

dayofyear(Now()) as DayOfYear,         ---find day of the year
dayofweek(Now()) as WeekdayUS,         ---find day of the week (number from 1 to 7, week starts on Sunday)
dayofweek_iso(Now()) as WeekdayEU,     ---find day of the week (number from 1 to 7, week starts on Monday)

week(Now())     as WeekNumUS,          ---week number, US standard
week_iso(Now()) as WeekNumEU           ---week numbeer, ISO standard

----------------------------MySQL------------------------------------------------------------------------------

select

Now(),                                
Date(Now())          as Today,                           
Year(Now())          as ThisYear,                           
Quarter(Now())       as ThisQuarter,                        
Month(Now())         as ThisMonth,                          
Day(Now())           as ThisDay,                            

dayofyear(Now())     as DayOfYear,
dayofmonth(Now())    as DayOfMonth,
dayofweek(Now())     as DayofWeek,   #1 = Sunday, 2 = Monday, …, 7 = Saturday)
weekday(Now())       as WeekdayNum,  #0 = Monday, 1 = Tuesday, … 6 = Sunday
           
weekofyear(Now())    as WeekNumUS,
week(Now())        	 as WeekNumUS   

Now()               |Today      |ThisYear |ThisQuarter |ThisMonth |ThisDay |
--------------------|-----------|---------|------------|----------|--------|
2017-10-26 17:03:43 |2017-10-26 |2017     |4           |10        |26      |


DayOfYear |DayOfMonth |DayofWeek |WeekdayNum |WeekNumUS |WeekNumUS |
----------|-----------|----------|-----------|----------|----------|
299       |26         |5         |3          |43        |43        |


------------------------- MS SQL Server----------------------------------------------------------------------------

select

getdate()              as Now,
Year(getdate())        as ThisYear,     
Month(getdate())       as ThisMonth,    
Day(getdate())         as Today       


Now                 |ThisYear |ThisMonth |Today |
--------------------|---------|----------|------|
2017-10-26 16:21:57 |2017     |10        |26    |


以上是关于sql 如何在SQL_vertica中提取部分日期的主要内容,如果未能解决你的问题,请参考以下文章

sql中如何提取从数据库中所获得时间的年份

sql如何按日期中的月份查询

sql 查询中 有12个月表 写一个查询从中提取所有日期

如何在 oracle sql 中提取两个日期之间的天数?

如何仅从 sql server 2008 中的日期中提取年份?

如何在 POSTGRESQL 中从 DATE 中提取年份