Forum Discussion

MJG2112's avatar
MJG2112
Icon for Advocate II rankAdvocate II
5 months ago
Solved

DateTime Options to Always Obtain Current UK Time

Hi. All of my reports contain a simple refresh timestamp using DateTime.LocalNow(). This is no longer giving me the desired result since DST happened in the UK. If I refresh a report on my desktop th...
  • MJG2112's avatar
    5 months ago

    V-yubandi-msft Thanks for code.  It didn't work but I used it as the basis for a solution that has fix the problem for me.

     

    = let
    // Use FixedUtcNow for a stable “refresh moment” during evaluation
    utcNow = DateTimeZone.FixedUtcNow(),
    year = Date.Year(DateTimeZone.RemoveZone(utcNow)),

    // UK DST rules: BST starts 01:00 UTC last Sunday in March
    // BST ends 01:00 UTC last Sunday in October
    lastSundayMarch = Date.StartOfWeek(#date(year, 3, 31), Day.Sunday),
    lastSundayOct = Date.StartOfWeek(#date(year,10, 31), Day.Sunday),

    bstStartUtc = #datetimezone(year, 3, Date.Day(lastSundayMarch), 1, 0, 0, 0, 0),
    bstEndUtc = #datetimezone(year,10, Date.Day(lastSundayOct), 1, 0, 0, 0, 0),

    isBST = utcNow >= bstStartUtc and utcNow < bstEndUtc,
    offset = if isBST then 1 else 0,

    ukNowZoned = DateTimeZone.SwitchZone(utcNow, offset),
    ukNow = DateTimeZone.RemoveZone(ukNowZoned)
    in
    ukNow