Show code in...     

  

 

All Functions Math Functions String Functions Logical Functions
Time Functions Statistical Functions Information Functions
Lookup & Reference Functions Database Functions Financial Functions

Time Functions

The only functions available in
ExcelWriterSE and ExcelWriterLE
are sum and average.

If start_date occurs after end_date, days360 returns a negative number. Dates should be entered by using the date function, or as results of other formulas or functions. For example, use date(2008,5,23) for the 23rd day of May, 2008.

The following returns the number of days between April 8, 2003 and July 19, 2003, based on a 360-day year.


	ws.cells("B4").formula = "=Days360(date(2003,4,8),date(2003,7,19),true)"
Time Functions
date*

Returns the number that represents the date in Microsoft Excel date-time code. Date takes three arguments: Year, Month, and Day. Year is a number from 1900 to 1999 in Microsoft Excel for Windows. Month is a number from 1 to 12 representing the month of the year. Day is a number from 1 to 31 representing the day of the month. To retrieve the Excel date-time code for Aug 9, 2000, and display it in cell B2, use,

	ws.cells("B2").formula = "=Date(2000,8,9)"
	
datevalue*

Returns the Excel date-time code of the date represented by text. Datevalue takes one argument, date_text, which represents a date in an Excel date format. For example, "1/30/2008" or "30-Jan-2008" are text strings within quotation marks that represent dates.

Using the default date system in Excel for Windows, date_text must represent a date from January 1, 1900, to December 31, 9999. Datevalue returns the #VALUE! error value if date_text is out of this range. If the year portion of date_text is omitted, datevalue uses the current year from your computer's built-in clock. Time information in date_text is ignored.

Excel stores dates as sequential serial numbers so 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,448 days after January 1, 1900.

The following takes the date string "12/20/2003" and returns the date-time code 37975.


	ws.cells("B2").formula = "=Datevalue("12/20/2003")
day*

Returns the day of the month (a number from 1 to 31) of a date represented in Excel date-time code. In the following example, 36747 is the Excel date-time code for Aug 9, 2000. To display the day of the month (9) in cell B2, use,

	ws.cells("B2").formula = "=Day(36747)"
	
days360*

Returns the number of days between two dates based on a 360-day year (twelve 30-day months), which is used in some accounting calculations.

Days360 takes three arguments, start_date, end_date, and method. Start_date and end_date are the two dates between which you want to know the number of days. Method is a logical value that specifies whether to use the U.S. or European method in the calculation:

Method valueDefinition
False or omittedU.S. (NASD) method. If the starting date is the 31st of a month, it becomes equal to the 30th of the same month. If the ending date is the 31st of a month and the starting date is earlier than the 30th of a month, the ending date becomes equal to the 1st of the next month; otherwise the ending date becomes equal to the 30th of the same month.
TrueEuropean method. Starting dates and ending dates that occur on the 31st of a month become equal to the 30th of the same month.

hour*

Returns the hour of a time value. The hour returned is given as an integer ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.). Hour takes one argument, a time-value. The time-value may be entered as,

  • A text string (for example, "6:45 PM")
  • A decimal number in Excel date-time code (for example, 0.78125, which represents 6:45 PM)
To display the return value of hour in cell B4, use,

	ws.cells("B4").formula = "=Hour(""6:45 PM"")"
	

Notice that the embedded string "6:45 PM" is within an additional set of double-quotes. ASP syntax requires that double-quotes embedded in a string be doubled. Alternatively, use single quotes:

	ws.cells("B4").formula = "=Hour('6:45 PM')"
	
minute*

Returns the minute, an integer from 0 to 59, corresponding to a time value. The time-value may be entered as,

  • A text string (for example, "31-Dec-00" or "12-31-00")
  • A number in Excel date-time code (for example, 35886, which represents the date 4-1-98)
To display the minute of the time value "4:48 PM" in cell B5, use,

	ws.cells("B5").formula = "=Minute(""4:48 PM"")"
	

Notice that the embedded string "4:48 PM" is within an additional set of double-quotes. ASP syntax requires that double-quotes embedded in a string be doubled. Alternatively, use single quotes:

	ws.cells("B5").formula = "=Minute('4:48 PM')"
	
month*

Returns the month, an integer from 1 (January) to 12 (December), corresponding to a date-value. The date-value may be entered as,

  • A text string (for example, "31-Dec-00")
  • A number in Excel date-time code (for example, 36891, which represents 31-Dec-00)
To display the month of the date-value "31-Dec-00" in cell B5, use,

	ws.cells("B6").formula = "=Month(""31-Dec-00"")"
	

Notice that the embedded string "31-Dec-00" is within an additional set of double-quotes. ASP syntax requires that double-quotes embedded in a string be doubled. Alternatively, use single quotes:

	ws.cells("B6").formula = "=Month('31-Dec-00')"
	
now*

Returns the time-value in Excel date-time code of the current date or time. This function takes no arguments. To display the current time in cell B7, use,

	'--- Format.number defines the display format of numbers, 
	'--- dates, and times.  18 will display the time as h:mm AM/PM.
	ws.cells("B7").format.number = 18 
	ws.cells("B7").formula = "=Now()"
	
second*

Returns the second, an integer in the range 0 to 59, corresponding to a a time-value in Excel date-time code. The time-value may be entered as,

  • A text string (for example, "13:50:25" or "1:50:25 PM")
  • A number in Excel date-time code (for example, 0.576678241, which represents the time 1:50:25 PM)
To display the second of the time value "1:50:25 PM" in cell B9, use,

	ws.cells("B9").formula = "=Second(""13:50:25"")"
	

Notice that the embedded string "13:50:25" is within an additional set of double-quotes. ASP syntax requires that double-quotes embedded in a string be doubled. Alternatively, use single quotes:

	ws.cells("B9").formula = "=Second('13:50:25')"
	
time*

Returns a fraction from 0 (00:00:00) to 0.99999999 (23:59:59) that represents a particular time. Time takes three arguments: hour, minute, and second. To display the fraction code for the time 12:25:30 in cell B10, use,

	ws.cells("B10").formula = "=Time(12,25,30)"
	
timevalue*

Returns the decimal number of the time represented by a text string. The decimal number is a value ranging from 0 (zero) to 0.99999999, representing the times from 0:00:00 (12:00:00 AM) to 23:59:59 (11:59:59 P.M.).

Timevalue takes one argument, time_text, a text string that represents a time in any one of the Microsoft Excel time formats; for example, "6:45 PM" and "18:45" text strings within quotation marks that represent time. Date information in time_text is ignored.

The following takes the time string "2:57 pm" and returns the decimal number 0.622917.


ws.cells("B10").formula = "=Timevalue("2:57 pm")
today*

Returns a Microsoft Excel date-time code value that represents today's date. The following example demonstrates displaying today's date in the format mm/dd/yyyy. For other display options, see Formatting Codes.

	ws.cells("B18").format.number = 14
	ws.cells("B18").formula = "=Today()"
	
weekday*

Returns a number from 1 to 7 identifying the day of the week corresponding to a value that represents a date. The date-value may be entered as,

  • A text string (for example, "31-Dec-00")
  • A number in Excel date-time code (for example, 36891, which represents 31-Dec-00)
To display the day of the week for "31-Dec-00" in cell B5, use,

	ws.cells("B11").formula = "=Weekday(""31-Dec-00"")"
	

Notice that the embedded string "31-Dec-00" is within an additional set of double-quotes. ASP syntax requires that double-quotes embedded in a string be doubled. Alternatively, use single quotes:

	ws.cells("B11").formula = "=Weekday('31-Dec-00')"
	
year*

Returns the year, an integer in the range 1900-9999, corresponding to a date-value. The date-value may be entered as,

  • A text string (for example, "31-Dec-00")
  • A number in Excel date-time code (for example, 36891, which represents 31-Dec-00)
To display the year for "31-Dec-00" in cell B5, use,

	ws.cells("B12").formula = "=Year(""31-Dec-00"")"
	

Notice that the embedded string "31-Dec-00" is within an additional set of double-quotes. ASP syntax requires that double-quotes embedded in a string be doubled. Alternatively, use single quotes:

	ws.cells("B12").formula = "=Year('31-Dec-00')"
	
*This function is not available in ExcelWriterSE, ExcelWriterLE, or ExcelWriterFree. The only functions available in ExcelWriterSE, ExcelWriterLE, and ExcelWriterFree are sum and average.



Copyright © 2005, SoftArtisans, Inc.