How to add current date and time with a specific format

Hello community
I’m new at using Studio X and I’m trying to use the option of sending an email with outlook capturing the current date the Subject line and current time in the body. The date has be in “mm/dd/yyyy” format and time has be in “hh:MM:ss PM” format.

I am unable to convert the date and time to the required format .Unable to include the date in the Subject line as well.
Can anyone pls help me out on this ? Thank you.

Hello @Sreya_Sinha, try this:

  1. Get Current Date and Time:
  • Use the “Get Current Date/Time” activity to retrieve the current date and time.
  1. Format Date:
  • After getting the current date, use the “Format Date” activity to format it in the “mm/dd/yyyy” format. Set the input date to the date you obtained in the previous step, and set the output format to “MM/dd/yyyy”. This will give you the formatted date.
  1. Format Time:
  • Similarly, use the “Format Date/Time” activity to format the current time in the “hh:MM:ss tt” format. Set the input date/time to the current time, and set the output format to “hh:mm:ss tt”. This will give you the formatted time in the desired format.
  1. Compose Email:
  • Now, use the “Compose Email” activity to create your email.
  • For the subject, you can directly enter your subject line text and include the placeholders for the formatted date and time. For example: “Report for {{FormattedDate}} - {{FormattedTime}}”.
  • For the body, enter your text and again use the placeholders for the formatted date and time. For example: “Hello, here’s the report for {{FormattedDate}} at {{FormattedTime}}.”
  1. Send Email:
  • Finally, use the “Send Email” activity to send the composed email.

Get Current Date/Time → Format Date → Format Time → Compose Email → Send Email

Hope it helps,
Cheers! :slight_smile:

Hi @Sreya_Sinha

Step 1: Capture Current Date and Time

  1. Add the “Get Time Now” activity.
  2. In the “Output” section, create two variables:
    • Variable Name: CurrentDate
    • Variable Name: CurrentTime

Step 2: Format Date and Time

  1. Add the “Format Value” activity.
  2. In the “Value to format” field, select the CurrentDate variable.
  3. In the “Format” field, enter MM/dd/yyyy to format the date as “mm/dd/yyyy”.
  4. Create a new variable:
    • Variable Name: FormattedDate
  5. Repeat the above steps to format the time:
    • In the “Value to format” field, select the CurrentTime variable.
    • In the “Format” field, enter hh:mm:ss a to format the time as “hh:mm:ss AM/PM”.
    • Create a new variable:
      • Variable Name: FormattedTime

Step 3: Compose Email

  1. Add the “Send Outlook Mail Message” activity.
  2. In the “Subject” field, compose your subject text and include the FormattedDate variable:
    • For example: "Daily Report - " + FormattedDate
  3. In the “Body” field, compose your email content and include the FormattedTime variable.

Step 4: Send Email

  1. Complete the “Send Outlook Mail Message” activity by adding the recipient’s email address and other necessary details.

Hope it helps!!

Hi @Sreya_Sinha

Welcome to the forums

You can also use Set Variable Value and declare a variable let say

strTimeFormat = Now.ToString(“MM/dd/yyyy hh:mm:ss tt”)

Now you can use strTimeFormat into the email

Hope this may help you

Thanks,
Srini

Hi. Thank you for your suggestion. it is working fine.

@Sreya_Sinha

Set Variable Value and declare a variable let say

strTimeFormat = Now.ToString(“MM/dd/yyyy HH:mm:ss tt”)

Now you can use strTimeFormat into the email

Hope it helps!
Regards

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