To use the startOfYesterday function from date-fns you first need to install the library. You can install it using npm by running the following command in your terminal.
21 chars2 lines
Once installed, you can import the startOfYesterday function and use it in your code.
index.tsx151 chars7 lines
The startOfYesterday function returns a new date object set to the start of yesterday (i.e. 12:00:00 AM).
You can also use the function to set the start of yesterday for a specific timezone.
index.tsx215 chars8 lines
In the example above, we used the zonedTimeToUtc function from date-fns-tz to convert the startOfYesterday date object to the UTC timezone. We passed in the timezone string as the second argument to zonedTimeToUtc. This returned a new date object set to the start of yesterday in the America/New_York timezone (i.e. 5:00:00 AM UTC).
gistlibby LogSnag