C# date format question

I’ve tried searching, but I’m sure my problem is so basic that no-one really answers the specific question I’m asking. I’m working on sending out an E-mail via BPM and I am grabbing the ReqDueDate from the job head table. If I just grab that date and put it in the e-mail it looks like this.

image

what I would like it 12-19-2017

So I figured I would create a variable in the data directive that converts the date to a different format. I found the conversion x.ToString(format) in the GUI. Looks like it should work, I grab the field and try to use the conversion and I get an error. Shown below.

All of the examples I can find online just show something like this

image

I don’t understand what argument I’m missing.

well @rapat_mark had the answer

Did you try:
ttJobHeadRow.ReqDueDate.Value.ToString(“MM-dd-yyy”)

2 Likes

Just a stab…
convert(datetime, ttJobHeadRow.ReqDueDate, 101)

That’s SQL isn’t it? This is C# (it’s in a BPM)

You can just do a .ToString formate. so at the end add

I added the date below just so you can see how it is used. The .Replace is what removed the / and adds the - how you want above.

var date = DateTime.Now;

date.ToString(“d”).Replace("/","-");

Outputs:
1-5-2018

Obviously use your variable you have above. the var date is just to show you how the .toString should be used. You will use your RequestDate String.

DateTime.Now.Date will get you the short date I’m pretty sure. @mathis1337

Yes but he wanted - and not / which is what that returned. SO you have to do that anyways.

I wasn’t looking for the date that the e-mail was created. I was looking to reformat the required by date. So datetime.Now.Date doesn’t help me.

@mathis1337 and @Banderson I should have read the question more carefully. Cheers!

From what I can see, the following two lines produce the same results:

ttJobHeadRow.ReqDueDate.Value.ToString("MM/dd/yyyy");
string.Format("{0:d}", ttJobHeadRow.ReqDueDate);
1 Like