This topic is locked

Fomatting Email Date and Time

6/25/2018 12:38:09 PM
ASPRunner.NET General questions
S
swiersman author

All,
Looking for a way to format my DateTime field called "Completed Date" so that it appears with the following format: MM/DD/YYYY in the email Before Edit event
It is stored in the DB as "YYYY-MM-DD HH:MM:SS"
I tried the following in the body and it does not work: "Completed Date: " + values["Completed Date"].ToString("MM'/'DD'/'YYYY")
I also have a field called "Completed Time" and would like to format that as "HH:MM"
Any help would be greatly appreciated,
Scott

H
heilmanmd 6/25/2018

What I have found working btwn the DB and ASP Runner for date / time data is following
first you gotta find out how Asp runner is translating your db date into a string and what it looks like
forget what is stored in your DB it's meaningless
so...
in your before email event
string aspdate = values["dateField"].ToString(); // this assigns whatever ASP Runner formats / translates the DB date into a string
to view the above aspdate string
pass the value to your javascript on load event as such
pageObject.setProxyValue("aspdate",aspdate);
then in your javascript on load event
alert("here's what asp runner formated the DB date to " + proxy["aspdate"]);
now you know what the aspdate string looks like and from there you can format it however you wish
Hope this helps

S
swiersman author 6/25/2018

Thanks heilman,
I can actually see it in the email generated when I replace the prior with "Completed Date: " + values["Completed Date"].ToString()
It Looks like this in the email: Completed Date: 2018-06-20 00:00:00.
You mention I can now format this. How would I go about doing so?
Thanks....

H
heilmanmd 6/25/2018

Well
I'm assuming the following

  1. your using ASP Runner .NET

    2 ) and thus you are coding your events in C#

    3 ) and that you can put the email: Completed Date: 2018-06-20 00:00:00 into some string called XXX
    c# has many string functions
    like XXXX.Substring(ZZ,YY) XXXXX.Replace("XXX","YYY") etc...
    so have at it and do the old string manipulation to be what ever you wish it to be...
    for more about C # String Functions check out https://www.completecsharptutorial.com/csharp-articles/csharp-string-function.php
    Best

    Mark, Big Timber MT

S
swiersman author 6/29/2018

Thanks Mark,
I tried the below but still get the DateTime field outcome of: 2018-06-20 00:00:00 in each field.

Any idea what I am doing wrong?
Thanks,
Scott
BEFORE RECORD ENTERED EVENT
if (values["Status"] == "INT Request Complete")

{
DateTime dtCompletedDate = DateTime.Parse(values["Completed Date"]);

DateTime dtCompletedTime = DateTime.Parse(values["Completed Time"]);

string email = "scott.wiersman@ropesgray.com";

string from = "release.management@ropesgray.com";

string msg = "DETAILS:" + Environment.NewLine

  • "" + Environment.NewLine

    + "Completed Date: " + dtCompletedDate.Date.ToString() + Environment.NewLine
  • "" + Environment.NewLine**
  • "Completed Time: " + dtCompletedTime.ToString("hh.mm tt") + Environment.NewLine**
  • "Please use following link to review complete details in the Archive Console: " + Environment.NewLine
  • "http://onlinedeployment/RequestArchive/dbo_DEPLOYMENT_CONSOLE_ARCHIVE/list";;
    string subject = "A Deployment Request to INTEGRATION has been COMPLETED - " + values["Request Title"].ToString();

    XVar attachments = XVar.Array();

    // Attachments description. The 'path' is required. Others parameters are optional.

    // attachments = new XVar(

    // 0, new XVar("path", MVCFunctions.getabspath("files/1.jpg")),

    // 1, new XVar("path", MVCFunctions.getabspath("files/2.jpg"), "name", "image.jpg")) ;
    XVar result;

    result = MVCFunctions.runner_mail(new XVar("to", email, "subject", subject, "body", msg, "from", from, "attachments", attachments));

    // You can manually overwrite SMTP settings

    // result = MVCFunctions.runner_mail(new XVar("to", email, "subject", subject, "body", msg, "from", from, "attachments", attachments,

    // "host", "somehost", "port", 25, "username", "smtpUserName", "password", "password"));

    if(!result["mailed"])

    {

    MVCFunctions.EchoToOutput(result["message"]);

    }

    }

H
heilmanmd 6/30/2018
  • "Completed Date: " + dtCompletedDate.Date.ToString() + Environment.NewLine
  • "" + Environment.NewLine
  • "Completed Time: " + dtCompletedTime.ToString("hh.mm tt") + Environment.NewLine
    converting a DATETIME field into a string formatted output...
    Well, Tons of help on the internet for doing that, just search ( google ) away
    Below URL is jus one of the HUNDREDS of links out there on how to do this
    http://www.csharp-examples.net/string-format-datetime/
    Should help you on your way
    Best

    Mark

    Big Timber, MT, USA

jadachDevClub member 6/30/2018

I do it like so:

"+String.Format("{0:dddd, MMMM d, yyyy}", Convert.ToDateTime((string)values["CompletedDate"])
T
Tim 7/5/2018



I do it like so:

"+String.Format("{0:dddd, MMMM d, yyyy}", Convert.ToDateTime((string)values["CompletedDate"])



Thanks Jerry for the clear, straightforward answer. This helped me a ton. It's often difficult to translate the C# code found in Google searches to the particulars of ASPRunner syntax. At least for the "fake programmers" like me (hey, that's why I use ASPR!).
Thanks,

Tim