none
Format a Datetime using StreamWritter in Asp.Net RRS feed

  • Question

  • Hi there,

     I'm using a StreamWriter to create a report in Excel.Even having the line like in the picture, in the report appears with the format "DD/MM/YYYY". I tried using string.Format before, but it doesn't work. So any idea that you have it would be useful.


    Thanks,

    Alvaro. 






    • Edited by Aivalo Thursday, February 7, 2019 11:52 AM
    Wednesday, February 6, 2019 5:43 PM

Answers

  • At the end, I used this format. The keys are the format of "=\"" + Date + "\"" and convert to Universal time.             string startDate = "=\"" + Convert.ToDateTime(StartDate).ToUniversalTime().ToString("yyyy/MM/dd").Replace(@"/", "-") + "\"";

    Thanks,

    Alvaro.

    • Marked as answer by Aivalo Thursday, February 7, 2019 3:40 PM
    Thursday, February 7, 2019 3:28 PM

All replies

  • Not knowing how you have coded this the first thought is you need to format the date something like this.

    Range rg = (Excel.Range)worksheetobject.Cells[1,1];
    rg.EntireColumn.NumberFormat = "MM/DD/YYYY";


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, February 6, 2019 5:51 PM
    Moderator
  • Hi Aivalo,

    Thank you for posting here.

    For your question, if you want to format "DD/MM/YYYY", you could try the code below with "dd/MM/yyyy".

        string s = DateTime.Now.ToString("dd/MM/yyyy");

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 7, 2019 3:37 AM
    Moderator
  • Thank you fr your answer,I think there was a problem with the picture.

    You can check the way that I'm creating the report. I don't have access to the range of the cells.


    • Edited by Aivalo Thursday, February 7, 2019 10:17 AM
    Thursday, February 7, 2019 9:49 AM
  • At the end, I used this format. The keys are the format of "=\"" + Date + "\"" and convert to Universal time.             string startDate = "=\"" + Convert.ToDateTime(StartDate).ToUniversalTime().ToString("yyyy/MM/dd").Replace(@"/", "-") + "\"";

    Thanks,

    Alvaro.

    • Marked as answer by Aivalo Thursday, February 7, 2019 3:40 PM
    Thursday, February 7, 2019 3:28 PM