ckrusen
(Calvin Krusen)
March 7, 2017, 6:52pm
1
I’ve got a Data Directive that sends out an email when a Packer is marked shipped (or when the Tracking# changes).
I’ve recently added the Shipping date to the email’s body, but the format includes a time of “12:00:00 AM”
Here’s the code:
NewEmailBody = NewEmailBody + "<b>Shipment Date: ";
NewEmailBody = NewEmailBody + ttShipHead_Row.ShipDate + "</b><br><br>";
That yields:
How do I format ttShipHead_Row.ShipDate as mm/dd/yyyy ?
Since it’s stored as a datetime, you can try formatting the datetime as a string with the format you want.
ttShipHead_Row.ShipDate.ToString("MM-dd-yyyy")
ckrusen
(Calvin Krusen)
March 7, 2017, 7:01pm
3
Thanks. I tried
ToString("d")
per the following MS example
Console.WriteLine(thisDate.ToString("d")); // Displays 3/15/2008
I’ll give the full “dd/MM/yyyy” a try
There are many ways to format your date, it’s just a matter of picking the one you want for the scenario.
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
ckrusen
(Calvin Krusen)
March 7, 2017, 7:03pm
6
I get “There is at least one compilation error. ” when trying to save with the .ToString(…)
ckrusen
(Calvin Krusen)
March 7, 2017, 7:09pm
8
With
I get an error when trying to save the Data Directive
Try creating your string variable first, then using the String.Format method to modify the string as @Mark_Wonsil provided above.
string newDate = ttShipHead_Row.ShipDate.ToString();
newDate = String.Format("{0:M/d/yyyy}", newDate);
1 Like
ckrusen
(Calvin Krusen)
March 7, 2017, 7:17pm
10
That saves/compiles okay. But still displays as
Are you displaying your new variable or are you still displaying ttShipHead_Row.ShipDate?
ckrusen
(Calvin Krusen)
March 7, 2017, 7:19pm
12
Yup.
And I’m sure the email I got was from a packer edited after the changes (I tweak the Tracking number)
EDIT:
Why is newDate being declared as a string ?
ckrusen
(Calvin Krusen)
March 7, 2017, 7:20pm
13
Just to be clear. This is in the Custom Code of a Data Directive’s “Execute Custom Code” block
Can you try this:
string newDate = String.Format("{0:d}", ttShipHead_Row.ShipDate);
Did you disable, re-enable the BPM in order to force a save of the new code?
ckrusen
(Calvin Krusen)
March 7, 2017, 7:34pm
16
No. I never do that. Should I always do that? Or are you thinking some sort of glitch?
Think you replied to the wrong comment
1 Like
ckrusen
(Calvin Krusen)
March 7, 2017, 7:35pm
18
I replied to the right comment, but I had Your post highlighted.
ckrusen
(Calvin Krusen)
March 7, 2017, 7:37pm
19
string newDate = String.Format("{0:d}", ttShipHead_Row.ShipDate);
This finally worked.
I’m glad it took others some time to figure it out. Now I don’t feel so alone
Hah good, such a simple one too!! Wasn’t thinking straight, otherwise we could have solved this in one post.