How to use Datetime offset in U-SQL?

Subhodeep Chakraborty 21 Reputation points
2021-03-24T14:35:32.163+00:00

Hello All,

i am trying to get current system time as
DECLARE @now Datetime= DateTime.Now();

Here I am getting PST time but i want to display EST time.
So how can I achieve this?

Azure Data Lake Analytics
0 comments No comments
{count} votes

Accepted answer
  1. Saurabh Sharma 23,816 Reputation points Microsoft Employee
    2021-03-25T13:58:40.85+00:00

    @Subhodeep Chakraborty Thanks for using Microsoft Q&A !!

    You can use Function like below to convert local DateTime to specific timezone -

    DECLARE @func Func<DateTime,DateTime> = (d) => {  
                                            TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");  
                                            DateTime.SpecifyKind(d, DateTimeKind.Local);  
                                            DateTime estTime = TimeZoneInfo.ConvertTime(d, cstZone);  
    return estTime;                                                                         
    };  
      
    @data =   
        SELECT data FROM   
    ( VALUES   
       (DateTime.UtcNow)) AS T(data);  
      
      
    @result =  
        SELECT @func(data).ToString("dd-MM-yyyyThh:mm:ss") AS data FROM @data;  
      
    OUTPUT @result  
    TO "datafolder/data.csv"    
    USING Outputters.Tsv();  
    

    81539-image.png

    Result:
    81370-image.png

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Subhodeep Chakraborty 21 Reputation points
    2021-03-25T14:47:19.16+00:00

    Hi @Saurabh Sharma ,

    This Works sweet. Thank you.
    Also Can you please tell me, How I can Append this converted EST Datetime in the output file name?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.