Forum Discussion

JustinL22's avatar
JustinL22
Contributor
10 months ago

How to keep date from excel in the same format

I am currently setting a date in excel and extracting that date to be used as a variable. I need the variable to be displayed in the format DD/MM/YY so in excel I have formatted the cell so it displays that way e.g. 06/02/24. However when testcomplete gets the data from the excel cell it sets the variable in the format DD/MM/YYYY e.g. 06/02/2024

How can I get it to keep the data exactly how it's being displayed in excel?

Thanks

    • JustinL22's avatar
      JustinL22
      Contributor

      So not something that can be done just using the get excel value then it has to be then coded?

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        Unfortunately not. 

        Excel stores dates as sequential serial numbers so that they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900.

        What you see in Excel, is a visual representation of a formatted date.

        Certain Excel drivers will perform some sort of conversion to retrieve the value in a certain format. Which is then left to the developer to format the value as they wish.