DateTime part function in Kusto | How to get Year, Month and Day from DateTime | KQL Tutorial 2022

Topic: DateTime part function in Kusto Query Language.

In this article, we are going to learn about datetime_part function, this function is very helpful and we can extract different parts of the data by using this function so it extracts the requested data part as the integer value. Kusto Query Language is a powerful tool to explore your data and discover patterns, identify anomalies and outliers, create statistical modeling, and more. The query uses schema entities that are organized in a hierarchy similar to SQL's: databases, tables, and columns.


 //datetime_part -- Extracts the requested date part as an integer value.  
 Part supported  
 Year  
 Quarter  
 Month  
 week_of_year  
 Day  
 DayOfYear  
 Hour  
 Minute  
 Second  
 Millisecond  
 Microsecond  
 Nanosecond  
   

 //Let's create a table Customer  
 //.drop table Customer  
 .create table Customer (CustomerId: long, FName: string,LName:string, Salary: int,hiredate:datetime)   
  .ingest inline into table Customer <|  
 1,Aamir,Shahzad,2000,2021-11-28T04:52:43.8745893Z  
 2,Raza,ALI,4000,2018-11-28T04:52:43.8745893Z  
 3,Lisa,Rivers,50000,2021-12-28T04:52:43.8745893Z  
 4,steve,Ladson,1000,2010-09-28T04:52:43.8745893Z  
 5,Robert,Jr,500,2015-01-20T04:52:43.8745893Z  
 6,aamir,ali,1000,2005-03-01T04:52:43.8745893Z  
   
 Customer  
 | extend   
 year=datetime_part('year',hiredate)  
 ,Quarter=datetime_part('Quarter',hiredate)  
 ,Month=datetime_part('Month',hiredate)  
 ,week_of_year=datetime_part('week_of_year',hiredate)  
 ,Day=datetime_part('Day',hiredate)  
 ,DayOfYear=datetime_part('DayOfYear',hiredate)  
 ,Hour=datetime_part('Hour',hiredate)  
 ,Minute=datetime_part('Minute',hiredate)  
 ,Second=datetime_part('Second',hiredate)  
 ,Millisecond=datetime_part('Millisecond',hiredate)  
 ,Microsecond=datetime_part('Microsecond',hiredate)  
 ,Nanosecond=datetime_part('Nanosecond',hiredate)  

Video Demo: DateTime part function in Kusto | How to get Year, Month and Day from DateTime | KQL Tutorial 2022

No comments:

Post a Comment