I'm on BST and have now found that the database source i am using always uses UTC. I'm trying to get the following to compare with the UTC time now and not GMT but can't see how to do it.
Where is the utc date that you are receiving coming from? What format is it in? For example it could be an ISO format date, or milliseconds (or seconds) from the epoch time.
It's coming from an API link that is then read as a CSV file.
Example is;
{"Delivery Date":"23/04/2025","Registered DFS Participant":"OAKTREE POWER LIMITED","DFS Unit ID":"OAKTRE-09","DFS Volume MW":2,"From":"17:30","To":"18:00","Service Requirement Type":"Live","Utilisation Price GBP per MWh":177,"Status":"Rejected","North Scotland":0,"South and Central Scotland":0,"North East England":0,"North West England":0,"Yorkshire":0,"East Midlands":0,"West Midlands":0,"London":0,"East England":0,"South East England":0,"South West England":0,"Southern England":0,"South Wales":0,"Other":2,"Total":2,"North Wales Merseyside and Cheshire":0}
One way would be in a function node, to build an ISO date from the object, so for the example you show create the string "20250423T180000Z" then use that to create a Date object, using Date.parse(). Then you can compare that to the current time created using `new Date(). Something like this (untested)
const splitDate = msg.payload["Delivery Date].split('/')
const splitTo = msg.payload.To.split(':')
const dateStr = `${splitDate[2]}${splitDate[1]}${splitDate[0]}T${splitTo[0]}${splitTo[1]}00Z`
const delivery = Date.parse(dateStr).getTime()
const now = new Date().getTime
if ( delivery < now ) {
// ...
}
Thanks, but I’m not really wanting to change the data.
The data from the source is in UTC time so I'm trying to compare it with the current time on the Pi but that’s in BST time. I'm really wanting to compare it with current UTC time. Moment docs show using moment.utc but I can't seem to get that to work.
My suggestion does not change the data, it fetches the current time, converts it to milliseconds since the Beginning (UTC) and compares it to the time in the data.