none
What is the recommended way to insert today's date in a cell, as a constant? RRS feed

  • Question

  • I have been using the following code:

    private void InsertDate(string dstCoordinates)
    {
        Range dstRange   = worksheet.get_Range(dstCoordinates);
        dstRange.Formula = "=TODAY()";
        dstRange.Locked  = true;
    }
    

    But I need the date to be evaluated once, when it is inserted in the cell. From that moment on, the value should be constant.

    That value seems to be stored internally as double.

    TIA

    Thursday, August 7, 2014 12:00 AM

Answers

  • Dear self:

    There you go...

    dstRange.Value2 = DateTime.Now.ToOADate();
    dstRange.NumberFormat = "m/d/yyyy"

    You are welcome.

    • Marked as answer by Travis Banger Friday, August 8, 2014 1:24 AM
    Friday, August 8, 2014 1:24 AM

All replies

  • Perhaps what I need is a function as follows:

    string today = ExcelEvaluate("=TODAY()");
    dstRange.value2 = today;

    Thursday, August 7, 2014 12:08 AM
  • Dear self:

    There you go...

    dstRange.Value2 = DateTime.Now.ToOADate();
    dstRange.NumberFormat = "m/d/yyyy"

    You are welcome.

    • Marked as answer by Travis Banger Friday, August 8, 2014 1:24 AM
    Friday, August 8, 2014 1:24 AM
  • Thanks for sharing your solution here, Travis!

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, August 8, 2014 6:51 AM
    Moderator