locked
Newbie: change datetime output RRS feed

  • Question

  • User369575276 posted

    Hi,

    I want to change the following

    <input OTHER CODE value="@DateTime.Now.ToString("yyyy")-01-01">

    which displays 2019-01-01

    To something that displays 2018-11-01

    This <g class="gr_ gr_88 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="88" data-gr-id="88">newbie</g> brain is on Oxycondon due to a broken arm so I'm stuck. A plain <g class="gr_ gr_224 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="224" data-gr-id="224">html</g> date value didn't parse.

    Help?

    Friday, January 18, 2019 2:48 AM

Answers

  • User303363814 posted

    If you want the first of November as a string then just type it in  … you don't need all that DateTime stuff

    value = "2018-11-01"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 12:31 PM

All replies

  • User-1716253493 posted
    @DateTime.Now.AddMonths(-1).ToString("yyyy-MM")

    Do you want to operate datetime?

    Friday, January 18, 2019 3:40 AM
  • User369575276 posted

    Thanks, that <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="5" data-gr-id="5">kindof</g> worked. I tried

    @DateTime.Now.AddMonths(-3).ToString("yyyy-MM-dd")

    and it covers the period at least. I'll give it a try without the day spec.

    Also, it's not my code, I am just <g class="gr_ gr_35 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="35" data-gr-id="35">tomaintain</g> it until the service is retired.

    Friday, January 18, 2019 6:22 AM
  • User-1716253493 posted

    For complete datetime operation you can follow this

    https://docs.microsoft.com/en-us/dotnet/api/system.datetime.addmonths?view=netframework-4.7.2

    Friday, January 18, 2019 7:23 AM
  • User369575276 posted

    Thanks, however I c an't see why this doesn't work. I get parser error.

    value="DateTime( 2018, 11, 01).ToString("yyyy-mm-dd")">

    Tuesday, January 22, 2019 10:14 AM
  • User303363814 posted

    If you want the first of November as a string then just type it in  … you don't need all that DateTime stuff

    value = "2018-11-01"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 12:31 PM
  • User369575276 posted

    Indeed, but wherer's the fun in that?

    Is there a way to do it in C# as well?

    Tuesday, January 22, 2019 1:42 PM
  • User303363814 posted

    value = "2018-11-01"; is c#!

    Do you mean "Is it possible to do it in a very long winded difficult, slow and unnecessary way"?  Sounds like a fun challenge!  How about?

    var value = $"{int.Parse(string.Join("", (new []{50,48,49,56}).Select(l => (char)l)))}-{(new [] {"Larry", "Curly", "Mo"}).Length * 4 - 1}-0{(Int16)((new Random()).Next(1)+1)}";
    

    That's bound to have anyone reading your code scratching their head!

    Tuesday, January 22, 2019 11:19 PM