How do I get Yesterdays day

Hello!

I have, at least for me, an interesting problem:
Every day I need to save a value from the day before into a csv file.
Therefore I create a file based on month/year and create a line for each day and the respective value.
The problem I have is at months end/months beginning...
How do I get yesterdays date? :slight_smile:

Thank you!

This is my current code:

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth()+1; 
var day = (d.getDate()-1);
if(month.toString().length == 1) {
var month = '0'+month;
}
msg.filename = "/mnt/data/PVDaten/Tagesdaten"+year+month+".csv";

msg.payload = msg.payload.toString()
msg.payload = day+","+(Number(msg.payload)/10)

return msg;

deduct the day before accessing year or month as they might change (e.g. deducting 1 from the 1st jan should give you 31st dec)

var d = new Date();
d.setDate(d.getDate() - 1);
var year = d.getFullYear();
var month = d.getMonth()+1; 
var day = d.getDate();
//... your code ...

:joy:
that easy...
thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.