How to obtain a timestamp from a date with dd-mm-yyyy format

Hi.

How to obtain a timestamp from a date with dd-mm-yyyy format?

I don't see how to use magic text to do this.

Maybe using javascript ? Some guidance or an example?

Thanks a lot.
 

Winny57

Member
Hello, what exactly do you want to do? Have today's date like this?
<CODE> [dayofmonth]/[month_digit]/[year]
[dayofweek]/[month]/[year]
</CODE>
 
Hello, what exactly do you want to do? Have today's date like this?
<CODE> [dayofmonth]/[month_digit]/[year]
[dayofweek]/[month]/[year]
</CODE>
Hi.

It's not today's date. It's another date at dd-mm-yyyy format and I need to obtain an timestamp in Ms from this date

Thanks for attention
 
Maybe using a formula but I don't know this formula and also how to use a formula in MD
Asked CHATGPT for na fórmula and it gives me this.

function calculateTimestampWithoutGetTime(dateString) {
// Parse date components
const [day, month, year] = dateString.split('-').map(Number);

// Calculate timestamp in milliseconds manually
const secondsPerMinute = 60;
const minutesPerHour = 60;
const hoursPerDay = 24;
const millisecondsPerSecond = 1000;
const daysPerYear = 365.25; // Account for leap years

// Calculate total days since Unix epoch
const yearsSinceEpoch = year - 1970;
const leapDays = Math.floor((yearsSinceEpoch + 1) / 4); // Account for leap years
const daysSinceEpoch =
yearsSinceEpoch * daysPerYear + leapDays + (month - 1) * 30 + day - 1;

// Convert days to milliseconds
const timestampMs =
daysSinceEpoch * hoursPerDay * minutesPerHour * secondsPerMinute * millisecondsPerSecond;

return timestampMs;
}

// Example usage:
const dateStr = '09-04-2024';
const timestampMs = calculateTimestampWithoutGetTime(dateStr);
console.log(timestampMs); // Output: 1718064000000 (milliseconds since January 1, 1970)

How may I use in MD to create a variable, for example?
 
Thanks.

Sorry but I don't know how to insert the code in my macro (see image, please)
 

Attachments

  • Screenshot_20240409_155522_MacroDroid.jpg
    Screenshot_20240409_155522_MacroDroid.jpg
    432.1 KB · Views: 6
For testing and leaning I am using a macro with a single she'll script action but am having a "bad date" return.

Any help?
 

Attachments

  • Screenshot_20240409_172554_MacroDroid.jpg
    Screenshot_20240409_172554_MacroDroid.jpg
    297.9 KB · Views: 6

Dm114

Well-known member
Sorry it's also my fault: I missed it in my first answer...

Be aware that the returned timestamp is UTC time. If you need local time, you'll have to add/subtract the time gap according to your time zone (and DST if any).
 
Last edited:
Top