Get tomorrow's date

So I have this time variable $(time Africa/Cairo "DD-MM-YYYY") that shows today’s date in the shown format, how can I make it so that it shows tomorrow’s date?

Hey @karimawi!

It’s much more complicated than just doing a +1d to the variable… Cairo is on the UTC+2 timezone, and luckily for you, you don’t have DST, otherwise this would just be impossible to manage.
So here’s how to get tomorrow’s date under the DD-MM-YYYY format for Cairo:

$(eval t = new Date(); t.setUTCHours(t.getUTCHours()+2); t.setUTCDate(t.getUTCDate()+1); t.toISOString().match(/\d{4}-\d{2}-\d{2}/)[0].split('-').reverse().join('-');)

Now, I think this is linked to the Muslim prayer times command, you could have continued in that topic, it would have been better actually, because if I didn’t make the link, you would have had a hard time figuring out how to make it work together, and you would have had to open another topic for something that could have been resolved quickly.

See, if you wanted to use that date for the command I helped you with yesterday, you’d need to use an alias, since the $(urlfetch) is called before any code is executed, therefore you can’t tell the API which date you’re fetching if you’re trying to do everything under one command.

So here’s how to implement the whole thing together:

!addcom !COMMAND_NAME -a=_COMMAND_NAME $(eval t = new Date(); t.setUTCHours(t.getUTCHours()+2); t.setUTCDate(t.getUTCDate()+1); t.toISOString().match(/\d{4}-\d{2}-\d{2}/)[0].split('-').reverse().join('-');)

!addcom _COMMAND_NAME $(eval a = $(urlfetch json http://api.aladhan.com/v1/timings/$(query)?latitude=30.053733&longitude=31.338610&method=5); if (a.code === 200) {t = a.data.timings; Object.keys(t).map(e => {d = t[e].split(':'); h = (d[0] % 12) || 12; t[e] = `${h}:${d[1]} ${h == d[0] ? 'AM' : 'PM'}`;}); `Fajr: ${t.Fajr} | Dhuhr: ${t.Dhuhr} | Asr: ${t.Asr} | Maghrib: ${t.Maghrib} | Isha: ${t.Isha}`} else {'There was an error'})

You just have to replace the three instances of COMMAND_NAME with the name you want to give your command. I made the alias command start with an underscore _, don’t replace that one.

1 Like

Thank you so much <3

1 Like

Is it possible to add the date at the beginning as 14-5-2022 just to clarify the date of the times? because the $(eval t = new Date(); [t.set](https://t.set/)UTCHours([t.get](https://t.get/)UTCHours()+2); [t.set](https://t.set/)UTCDate([t.get](https://t.get/)UTCDate()+1);) responds with unix not DD-MM-YYYY

I literally outplayed the bot, I just came up with the idea of finding the city that has the exact opposite timezone of my city so that it’s exactly a 1 day difference between us and I just used it instead, it’s Pacific/Kiritimati and it’s exactly 1 day ahead of my timezone, that’s probably the dumbest way to do it but the smartest way at the same time xD, idk I just used it for the date at the beginning.

1 Like

You need to keep the code complete, don’t pick up bits of it because of course it won’t work as you expect it.
I simply copy/pasted my code and it works just fine:

But I’m glad you found a workaround.

1 Like

I just added $(query) again instead of just pasting the same data of the original command $(eval t = new Date(); t.setUTCHours(t.getUTCHours()+2); t.setUTCDate(t.getUTCDate()+1); t.toISOString().match(/\d{4}-\d{2}-\d{2}/)[0].split('-').reverse().join('-');) and it worked as a charm.

1 Like