def write_date_time(*args)
      # Check for a cell reference in A1 notation and substitute row and column
      row, col, str, xf = row_col_notation(args)
      raise WriteXLSXInsufficientArgumentError if [row, col, str].include?(nil)

      # Check that row and col are valid and store max and min values
      check_dimensions(row, col)
      store_row_col_max_min_values(row, col)

      date_time = convert_date_time(str)

      if date_time
        store_data_to_table(NumberCellData.new(self, row, col, date_time, xf))
      else
        # If the date isn't valid then write it as a string.
        write_string(*args)
      end
    end
def write_date_time(*args)
      # Check for a cell reference in A1 notation and substitute row and column
      row, col, str, xf = row_col_notation(args)
      raise WriteXLSXInsufficientArgumentError if [row, col, str].include?(nil)

      # Check that row and col are valid and store max and min values
      check_dimensions(row, col)
      store_row_col_max_min_values(row, col)

      date_time = convert_date_time(str)

      if date_time
        store_data_to_table(NumberCellData.new(self, row, col, date_time, xf))
      else
        # If the date isn't valid then write it as a string.
        write_string(*args)
      end
    end
:call-seq:
   write_date_time (row, col, date_string [ , format ] )

 Write a datetime string in ISO8601 "yyyy-mm-ddThh:mm:ss.ss" format as a
 number representing an Excel date. format is optional.

 The write_date_time() method can be used to write a date or time
 to the cell specified by row and column:

     worksheet.write_date_time('A1', '2004-05-13T23:20', date_format)

 The +date_string+ should be in the following format:

     yyyy-mm-ddThh:mm:ss.sss

 This conforms to an ISO8601 date but it should be noted that the
 full range of ISO8601 formats are not supported.

 The following variations on the +date_string+ parameter are permitted:

     yyyy-mm-ddThh:mm:ss.sss         # Standard format
     yyyy-mm-ddT                     # No time
               Thh:mm:ss.sss         # No date
     yyyy-mm-ddThh:mm:ss.sssZ        # Additional Z (but not time zones)
     yyyy-mm-ddThh:mm:ss             # No fractional seconds
     yyyy-mm-ddThh:mm                # No seconds

 Note that the T is required in all cases.

 A date should always have a +format+, otherwise it will appear
 as a number, see
 {"DATES AND TIME IN EXCEL"}[#method-i-write_date_time-label-DATES+AND+TIME+IN+EXCEL]
 and {"CELL FORMATTING"}[#label-CELL+FORMATTING].
 Here is a typical example:

     date_format = workbook.add_format(:num_format => 'mm/dd/yy')
     worksheet.write_date_time('A1', '2004-05-13T23:20', date_format)

 Valid dates should be in the range 1900-01-01 to 9999-12-31,
 for the 1900 epoch and 1904-01-01 to 9999-12-31, for the 1904 epoch.
 As with Excel, dates outside these ranges will be written as a string.

 See also the date_time.rb program in the examples directory of the distro.


 == DATES AND TIME IN EXCEL

 There are two important things to understand about dates and times in Excel:

 1 A date/time in Excel is a real number plus an Excel number format.
 2 WriteXLSX doesn't automatically convert date/time strings in {#write()}[#method-i-write] to an Excel date/time.

 These two points are explained in more detail below along with some
 suggestions on how to convert times and dates to the required format.

 === An Excel date/time is a number plus a format

 If you write a date string with {#write()}[#method-i-write] then all you will get is a string:

     worksheet.write('A1', '02/03/04')   # !! Writes a string not a date. !!

 Dates and times in Excel are represented by real numbers, for example
 "Jan 1 2001 12:30 AM" is represented by the number 36892.521.

 The integer part of the number stores the number of days since the epoch
 and the fractional part stores the percentage of the day.

 A date or time in Excel is just like any other number. To have the number
 display as a date you must apply an Excel number format to it.
 Here are some examples.

     #!/usr/bin/ruby -w

     require 'write_xlsx'

     workbook  = WriteXLSX.new('date_examples.xlsx')
     worksheet = workbook>add_worksheet

     worksheet.set_column('A:A', 30)    # For extra visibility.

     number = 39506.5

     worksheet.write('A1', number)             #   39506.5

     format2 = workbook.add_format(:num_format => 'dd/mm/yy')
     worksheet.write('A2', number, format2)    #  28/02/08

     format3 = workbook.add_format(:num_format => 'mm/dd/yy')
     worksheet.write('A3', number, format3)    #  02/28/08

     format4 = workbook.add_format(:num_format => 'd-m-yyyy')
     worksheet.write('A4', number, format4)    #  28-2-2008

     format5 = workbook.add_format(:num_format => 'dd/mm/yy hh:mm')
     worksheet.write('A5', number, format5)    #  28/02/08 12:00

     format6 = workbook.add_format(:num_format => 'd mmm yyyy')
     worksheet.write('A6', number, format6)    # 28 Feb 2008

     format7 = workbook.add_format(:num_format => 'mmm d yyyy hh:mm AM/PM')
     worksheet.write('A7', number , format7)   #  Feb 28 2008 12:00 PM

 WriteXLSX doesn't automatically convert date/time strings

 WriteXLSX doesn't automatically convert input date strings into Excel's
 formatted date numbers due to the large number of possible date formats
 and also due to the possibility of misinterpretation.

 For example, does 02/03/04 mean March 2 2004, February 3 2004 or
 even March 4 2002.

 Therefore, in order to handle dates you will have to convert them to
 numbers and apply an Excel format. Some methods for converting dates are
 listed in the next section.

 The most direct way is to convert your dates to the ISO8601
 yyyy-mm-ddThh:mm:ss.sss date format and use the write_date_time()
 worksheet method:

     worksheet.write_date_time('A2', '2001-01-01T12:20', format)

 See the write_date_time() section of the documentation for more details.

 A general methodology for handling date strings with write_date_time() is:

 1. Identify incoming date/time strings with a regex.
 2. Extract the component parts of the date/time using the same regex.
 3. Convert the date/time to the ISO8601 format.
 4. Write the date/time using write_date_time() and a number format.
 For a slightly more advanced solution you can modify the {#write()}[#method-i-write] method
 to handle date formats of your choice via the add_write_handler() method.
 See the add_write_handler() section of the docs and the
 write_handler3.rb and write_handler4.rb programs in the examples
 directory of the distro.

 Converting dates and times to an Excel date or time

 The write_date_time() method above is just one way of handling dates and
 times.

 You can also use the convert_date_time() worksheet method to convert
 from an ISO8601 style date string to an Excel date and time number.