Broker/Data: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Favorite Futures: Futures
Posts: 202 since Mar 2013
Thanks: 426 given,
Date and Time Formatting; Day of Week
I've built myself an indi that when a trade occurs, it prints various things about the trade to several lists, that I then print out to the output window for use in Excel.
I'm currently using the following code to add the date and time of the trade:
Which in turn output:
20130907 (ie, 09/07/2013)
155759 (ie, 3:57:59p)
I was curious if anyone had a slick way of formatting the above code to format the outputs accordingly:
ToDay(Time) --> mm/dd/yyyy --> EX: 9/7/2013 (ie, not 09/07/2013)
ToTime(Time) --> hh:mm am/pm --> EX: 11:15 am or 2:13 pm (ie, no seconds and not 02:13 pm)
Also, I was curious if anyone knew of a way to grab the day of week from the Time property.
Finally, I would need to know what list type the newly formatted items would be (ie, int, double, string). For instance, ToDay() and ToTime() are current lists of type int, but would the newly formatted lists be of type string? Also, would the weekday list be a type string?
I know, pretty boring stuff, but I appreciate your help if you have the time.
Without checking (i.e. it might need adjusting - I'm not sure if "m" is for minute or month), you need something like this:
There are lots of different ways of doing this and using "yyyy-MM-dd HH:mm" is my favourite, but there are some named shortcuts which are simpler. Just google "c# DateTime format pattern yyyy" or similar.
It's a function of DateTime class - something like
As you say, this is really run-of-the-mill stuff. The Microsoft online documentation is great for simple reference like this. Just google "c# DateTime DayOfWeek" and you should see a link to the MSDN libraries in the first few search results, which will give you explanations and examples and links to other functionality in this area.
You can discover what your enemy fears most by observing the means he uses to frighten you.
The following user says Thank You to Adamus for this post: