I have this small code here:
@foreach (var date in ViewBag.MissingDays)
{
var isoDate = date.ToString("yyMMdd");
<div class="col-md-1">
<input type="checkbox" id="isoDate" name="isoDate" value="@isoDate" />
@isoDate
</div>
}
That will print out all the dates in my view that i missed, and like you can see it prints out them like "yymmdd yymmdd yymmdd" etc, but it's hard to know what weekday it is, so I would like to be "mo yymmdd tu yymmdd we yymmdd" so it's the two first letters of the day, how can I achive this?
You probably want to keep the value
part as it is - or ideally as yyyyMMdd
, as two-digit year formats are horrible - and just format the display part differently. I don't think there's anything to use two-letter month abbreviations - the abbreviated month names are in English cultures are normally three letters rather than two. (This varies by culture. I don't know of any English-based cultures which use two letters, but some other cultures do, such as German.)
I'd actually recommend using just the d
standard date format for display, or possibly D
(long rather than short) as that will then use an appropriate format for the culture - assuming the current thread's culture has been set appropriately. So something like:
@foreach (var date in ViewBag.MissingDays)
{
<div class="col-md-1">
<input type="checkbox" id="isoDate"
name="isoDate"
value="@date.ToString("yyyyMMdd", CultureInfo.InvariantCulture)" />
@date.ToString("D")
</div>
}
(The razor syntax may be slightly off - hopefully you'll be able to adapt it accordingly.)
I know you've said what you want the format to be, but I suspect you're thinking solely about users in your own culture. Do you know whether that format will be appropriate in other cultures? If all your users are guaranteed to be English, that's not such a problem - but in general you should avoid such assumptions.
See more on this question at Stackoverflow