Home > Software engineering >  Need script to generate email with date/time stamp
Need script to generate email with date/time stamp

Time:08-31

I want to create a script, or even batch, that outputs an email address with the date/time the script is run as part of the email, and puts it in the clipboard or outputs it to be copied. For example, if I run it, an email address is generated like this [email protected] I use this for testing so that I can then search error logs with a more exact time, making it easier to narrow down the errors. Below is what I have for Powershell, but I'm wanting to know how to make it more user friendly, like execute it with just a double-click

$curDate = Get-Date -Format "MM-dd-yy-HH-mm-ss"
"support-"   $curDate   "@clickdimensions.com" | clip

CodePudding user response:

The following code should do the trick. You can obviously improve where necessary to fit your need.

const generateEmail = () => {
    return document.querySelector('button').addEventListener('click', () => {
    const dateTime = new Date();
    let minutes = dateTime.getMinutes();
    if (dateTime.getMinutes().length < 2) {
        minutes = '0' dateTime.getMinutes();
    }
    const dateTimeNow = dateTime.getFullYear() '-' (dateTime.getMonth() 1) '-' dateTime.getDate() '-' dateTime.getHours() '-' minutes '-' dateTime.getSeconds();
    document.querySelector('p').innerText = 'support-' dateTimeNow '@domain.tld'
  });
}

generateEmail();

fiddle

CodePudding user response:

You can do it like this:

let email = "support-";
let date = new Date();

if ((date.getMonth() 1).toString().length < 2) {
  email  = "0";
}
email  = (date.getMonth() 1).toString();
email  = "-";
if (date.getDate().toString().length < 2) {
  email  = "0";
}
email  = date.getDate().toString();
email  = "-";
email  = date.getFullYear().toString().slice(2);
email  = "-";
if (date.getHours().toString().length < 2) {
  email  = "0";
}
email  = date.getHours().toString();
email  = "-";
if (date.getMinutes().toString().length < 2) {
  email  = "0";
}
email  = date.getMinutes().toString();
email  = "-";
if (date.getSeconds().toString().length < 2) {
  email  = "0";
}
email  = date.getSeconds().toString();
email  = "@clickdimensions.com";
console.log(email);

  • Related