question

SubhodeepChakraborty-1896 avatar image
0 Votes"
SubhodeepChakraborty-1896 asked SubhodeepChakraborty-1896 commented

How to use Datetime offset in U-SQL?

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SaurabhSharma-msft avatar image
0 Votes"
SaurabhSharma-msft answered SaurabhSharma-msft edited

@subhodeepchakraborty-1896 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.



image.png (56.0 KiB)
image.png (58.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SubhodeepChakraborty-1896 avatar image
0 Votes"
SubhodeepChakraborty-1896 answered SubhodeepChakraborty-1896 commented

Hi @SaurabhSharma-msft ,

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

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@subhodeepchakraborty-1896 Great to hear that it works. I need to check that as the function is not a constant-foldable expression in U-SQL. I will get back to you on the same.


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


0 Votes 0 ·

Thanks Saurabh...

0 Votes 0 ·