Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=180300024

Script, Scripting Language, VBScript elements, Server-Side VBScript Function Year, Month, Day, Hour, Minute, Second, Weekday Function

VBScript Date/Time Functions

Functions for manipulating date or time dexpression.

Year Function

last updated 9/21/2017

Create a Integer from a given date expression by getting the year part of the given date expression.

Syntax

Year(date)

Argument

dateRequired. Any valid Date expression that is used for evaluation.

Returns

Returns a Variant of Integer data subtype containing the value obtained from a given date expression by getting the year part of the given date expression.

Special returns of function:

datereturn valueNullNullEmptyUse Preset zero-Date""Run-time Error

Remarks

  • If date contains Null, Year function always returns Null.
  • If date contains Empty, Year function uses the preset zero-date as date argument.
  • If date is numeric, date is assumed to be equal to the days from zero-date.
  • If date is not a valid date expression, Year function returns Run-time error.
  • If the year part of date is omitted while day and month parts are present, the current year is assumed.
  • If day, month, and year parts are omitted, the day, month, and year parts of zero-date are assumed.

Requirement

1

Month Function

last updated 9/20/2017

Create an Integer with value between 1 and 12 inclusive for representing the 12 months of a year respectively from a given date expression by getting the month part of the given date expression.

Syntax

Month(date)

Argument

dateRequired. Any valid Date expression that is used for evaluation.

Returns

Returns a Variant of Integer data subtype containing an Integer with value between 1 and 12 inclusive for representing the 12 months of a year respectively obtained from a given date expression by getting the month part of the given date expression.

Special returns of function:

datereturn valueNullNullEmptyUse Preset zero-Date""Run-time Error

Remarks

  • The Month function always returns an integer between 1 and 12 inclusive for representing the 12 months of a year respectively.
  • If date contains Null, Month function always returns Null.
  • If date contains Empty, Month function uses the preset zero-date as date argument.
  • If date is numeric, date is assumed to be equal to the days from zero-date.
  • If date is not a valid date expression, Month function returns Run-time error.
  • If day, month, and year parts are omitted, the day, month, and year parts of zero-date are assumed.

Requirement

1

Day Function

last updated 9/18/2017

Create an Integer with value between 1 and 31 inclusive for representing the 31 days of a month respectively from a given date expression by getting the day part of the given date expression.

Syntax

Day(date)

Argument

dateRequired. Any valid Date expression that is used for evaluation.

Returns

Returns a Variant of Integer data subtype containing an Integer with value between 1 and 31 inclusive for representing the 31 day of a month respectively obtained from a given date expression by getting the day part of the given date expression.

Special returns of function:

datereturn valueNullNullEmptyUse Preset zero-Date""Run-time Error

Remarks

  • The Day function always returns an integer between 1 and 31 inclusive for representing the 31 days of a month respectively.
  • If date contains Null, Day function always returns Null.
  • If date contains Empty, Day function uses the preset zero-date as date argument.
  • If date is numeric, date is assumed to be equal to the days from zero-date.
  • If date is not a valid date expression, Day function returns Run-time error.
  • If day, month, and year parts are omitted, the day, month, and year parts of zero-date are assumed.

Requirement

1

Hour Function

last updated 9/19/2017

Create an Integer with value between 0 and 23 inclusive for representing the 24 hours of a day respectively from a given time expression by getting the hour part of the given time expression.

Syntax

Hour(time)

Argument

timeRequired. Any valid Date expression that is used for evaluation.

Returns

Returns a Variant of Integer data subtype containing an Integer with value between 0 and 23 inclusive for representing the 24 hours of a day respectively obtained from a given date expression by getting the hour part of the given date expression.

Special returns of function:

datereturn valueNullNullEmptyUse Preset zero-Date""Run-time Error

Remarks

  • The Hour function always returns an integer between 0 and 23 inclusive for representing the 24 hours of a day respectively.
  • If time contains Null, Hour function always returns Null.
  • If time contains Empty, Hour function uses the preset zero-date as time argument.
  • If time is numeric, time is assumed to be equal to the days from zero-date.
  • If time is not a valid time expression, Hour function returns Run-time error.
  • If hour, minute, and second parts are omitted, the hour, minute, and second parts of zero-date are assumed.

Requirement

1

Minute Function

last updated 9/20/2017

Create an Integer with value between 0 and 59 inclusive for representing the 60 minutes of an hour respectively from a given time expression by getting the minute part of the given time expression.

Syntax

Minute(time)

Argument

timeRequired. Any valid Date expression that is used for evaluation.

Returns

Returns a Variant of Integer data subtype containing an Integer with value between 0 and 59 inclusive for representing the 60 minutes of an hour respectively from a given time expression by getting the minute part of the given time expression.

Special returns of function:

datereturn valueNullNullEmptyUse Preset zero-Date""Run-time Error

Remarks

  • The Minute function always returns an integer between 0 and 59 inclusive for representing the 60 minutes of an hour respectively.
  • If time contains Null, Minute function always returns Null.
  • If time contains Empty, Minute function uses the preset zero-date as time argument.
  • If time is numeric, time is assumed to be equal to the days from zero-date.
  • If time is not a valid time expression, Minuter function returns Run-time error.
  • If hour, minute, and second parts are omitted, the hour, minute, and second parts of zero-date are assumed.

Requirement

1

Second Function

last updated 9/21/2017

Create an Integer with value between 0 and 59 inclusive for representing the 60 seconds of a minute respectively from a given time expression by getting the second part of the given time expression.

Syntax

Second(time)

Argument

timeRequired. Any valid Date expression that is used for evaluation.

Returns

Returns a Variant of Integer data subtype containing an Integer with value between 0 and 59 inclusive for representing the 60 seconds of a minute respectively from a given time expression by getting the second part of the given time expression.

Special returns of function:

datereturn valueNullNullEmptyUse Preset zero-Date""Run-time Error

Remarks

  • The Second function always returns an integer between 0 and 59 inclusive for representing the 60 seconds of a minute respectively.
  • If time contains Null, Second function always returns Null.
  • If time contains Empty, Second function uses the preset zero-date as time argument.
  • If time is numeric, time is assumed to be equal to the days from zero-date.
  • If time is not a valid time expression, Second function returns Run-time error.
  • If second part is omitted, the second part is assumed to be equal to 0.
  • If hour, minute, and second parts are omitted, the hour, minute, and second parts of zero-date are assumed.

Requirement

1

Examples

Examples of functions

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,dte,cmda,var:var=0
cmda=array("dte","Year(dte)","Month(dte)","Day(dte)","Hour(dte)","Minute(dte)","Second(dte)")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0  Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&amp;"),"  "," &nbsp;"),"""","&quot;"),"<","&lt;"),">","&gt;"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0  Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function

vars="dte=Null":dsp_x
vars="dte=Empty":dsp_x
vars="dte=0":dsp_x
vars="dte=2":dsp_x
vars="dte=Now":dsp_x
vars="dte=#10/12/2017 7:08:06 PM#":dsp_x
vars="dte=""10/12/2017 7:08:06 PM""":dsp_x
vars="dte=#10/12/2017 7:08:06#":dsp_x
vars="dte=#10/12/2017 19:08:06#":dsp_x
vars="dte=#10/12/2017#":dsp_x
vars="dte=#10/12#":dsp_x
vars="dte=#7:08:06 PM#":dsp_x
vars="dte=#7:08:06#":dsp_x
vars="dte=#19:08:06#":dsp_x
vars="dte=#19:08#":dsp_x
</script>
HTML Web Page In-line Output:
Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp
varsdte, TypeNameYear(dte), TypeNameMonth(dte), TypeNameDay(dte), TypeNameHour(dte), TypeNameMinute(dte), TypeNameSecond(dte), TypeNamedte=Null[], Null[], Null[], Null[], Null[], Null[], Null[], Nulldte=Empty[], Empty[1899], Integer[12], Integer[30], Integer[0], Integer[0], Integer[0], Integerdte=0[0], Integer[1899], Integer[12], Integer[30], Integer[0], Integer[0], Integer[0], Integerdte=2[2], Integer[1900], Integer[1], Integer[1], Integer[0], Integer[0], Integer[0], Integerdte=Now[3/27/2019 9:26:34 AM], Date[2019], Integer[3], Integer[27], Integer[9], Integer[26], Integer[34], Integerdte=#10/12/2017 7:08:06 PM#[10/12/2017 7:08:06 PM], Date[2017], Integer[10], Integer[12], Integer[19], Integer[8], Integer[6], Integerdte="10/12/2017 7:08:06 PM"[10/12/2017 7:08:06 PM], String[2017], Integer[10], Integer[12], Integer[19], Integer[8], Integer[6], Integerdte=#10/12/2017 7:08:06#[10/12/2017 7:08:06 AM], Date[2017], Integer[10], Integer[12], Integer[7], Integer[8], Integer[6], Integerdte=#10/12/2017 19:08:06#[10/12/2017 7:08:06 PM], Date[2017], Integer[10], Integer[12], Integer[19], Integer[8], Integer[6], Integerdte=#10/12/2017#[10/12/2017], Date[2017], Integer[10], Integer[12], Integer[0], Integer[0], Integer[0], Integerdte=#10/12#[10/12/2019], Date[2019], Integer[10], Integer[12], Integer[0], Integer[0], Integer[0], Integerdte=#7:08:06 PM#[7:08:06 PM], Date[1899], Integer[12], Integer[30], Integer[19], Integer[8], Integer[6], Integerdte=#7:08:06#[7:08:06 AM], Date[1899], Integer[12], Integer[30], Integer[7], Integer[8], Integer[6], Integerdte=#19:08:06#[7:08:06 PM], Date[1899], Integer[12], Integer[30], Integer[19], Integer[8], Integer[6], Integerdte=#19:08#[7:08:00 PM], Date[1899], Integer[12], Integer[30], Integer[19], Integer[8], Integer[0], Integer

Weekday Function

last updated 9/21/2017

Create an Integer with value between 1 and 7 inclusive for representing the 7 days of a week respectively from a given date expression by getting the default weekday part of the given date expression according to firstdayofweek setting.

Syntax

Weekday(date, [firstdayofweek])

Argument

dateRequired. Any valid Date expression that is used for evaluation.firstdayofweekOptional seting. Any valid Constant that is used to specify the first day of a week. If firstdayofweek argument is omitted, vbSunday or 1 is used and Sunday is assumed to be the first day of a week.

Settings

firstdayofweek argument

vbConstantValueDescriptionvbUseSystemDayOfWeek0Use National Language Support (NLS) API setting.vbSunday1(default)Sunday .vbMonday2Monday.vbTuesday3Tuesday.vbWednesday4Wednesday.vbThursday5Thursday.vbFriday6Friday.vbSaturday7Saturday.

Returns

Returns a Variant of Integer data subtype containing the Integer with value between 1 and 7 inclusive for representing the 7 days of a week respectively obtained from a given date expression by getting the week part of the given date expression according to firstdayofweek setting.

Return values of weekday function for default weekday

firstdayofweekSunMonTueWedThuFriSatvbSunday (1)1234567vbMonday (2)7123456vbTuesday (2)6712345vbWednesday (2)5671234vbThursday (2)4567123vbFriday (2)3456712vbSaturday (2)2345671

Special returns of function:

datereturn valueNullNullEmptyUse Preset zero-Date""Run-time Error

Remarks

  • Weekday function is used to obtain the defualt day of the week from a specified date and return a number to represent the weekday of the given date according to the specified firstdayofweek.
  • The firstdayofweek setting is used to specified the first weekday of the sequence of weekdays.
  • The numeric representation of weekday depends on the firstdayofweek setting, and the first day of week is always represented by the number 1 of the sequence of returning numbers.
  • The defualt firstdayofweek is vbSunday (1), the sequence of default weekdays is therefore equal to {Sunday, Monday, Tuesday, ...} and is represented by the sequence of returning numbers {1, 2, 3, ...} accordingly. If the firstdayofweek is set to vbMonday (2), the sequence of weekdays is therefore equal to {Monday, Tuesday, Wednesday, ...} and is still represented by the sequence of returning numbers {1, 2, 3, ...} accordingly. In other words, the default weekday of a date is always equal to return number plus firstdayofweek minus 1.

Requirement

1

Examples

Examples of function

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,dte,cmda,var:var=0
cmda=array("dte","Weekday(dte)","Weekday(dte,1)","Weekday(dte,2)","Weekday(dte,3)","Weekday(dte,4)","Weekday(dte,5)","Weekday(dte,6)","Weekday(dte,7)")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0  Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&amp;"),"  "," &nbsp;"),"""","&quot;"),"<","&lt;"),">","&gt;"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0  Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function

vars="dte=Null":dsp_x
vars="dte=Empty":dsp_x
vars="dte=0":dsp_x
vars="dte=2":dsp_x
vars="dte=Now":dsp_x
vars="dte=#10/12/2017 7:08:06 PM#":dsp_x
vars="dte=""10/12/2017 7:08:06 PM""":dsp_x
vars="dte=#10/12/2017 7:08:06#":dsp_x
vars="dte=#10/12/2017 19:08:06#":dsp_x
vars="dte=#10/12/2017#":dsp_x
vars="dte=#10/12#":dsp_x
vars="dte=#7:08:06 PM#":dsp_x
vars="dte=#7:08:06#":dsp_x
vars="dte=#19:08:06#":dsp_x
vars="dte=#19:08#":dsp_x
</script>
HTML Web Page In-line Output:
Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp
varsdte, TypeNameWeekday(dte), TypeNameWeekday(dte,1), TypeNameWeekday(dte,2), TypeNameWeekday(dte,3), TypeNameWeekday(dte,4), TypeNameWeekday(dte,5), TypeNameWeekday(dte,6), TypeNameWeekday(dte,7), TypeNamedte=Null[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Nulldte=Empty[], Empty[7], Integer[7], Integer[6], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integerdte=0[0], Integer[7], Integer[7], Integer[6], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integerdte=2[2], Integer[2], Integer[2], Integer[1], Integer[7], Integer[6], Integer[5], Integer[4], Integer[3], Integerdte=Now[3/27/2019 9:26:34 AM], Date[4], Integer[4], Integer[3], Integer[2], Integer[1], Integer[7], Integer[6], Integer[5], Integerdte=#10/12/2017 7:08:06 PM#[10/12/2017 7:08:06 PM], Date[5], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integer[7], Integer[6], Integerdte="10/12/2017 7:08:06 PM"[10/12/2017 7:08:06 PM], String[5], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integer[7], Integer[6], Integerdte=#10/12/2017 7:08:06#[10/12/2017 7:08:06 AM], Date[5], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integer[7], Integer[6], Integerdte=#10/12/2017 19:08:06#[10/12/2017 7:08:06 PM], Date[5], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integer[7], Integer[6], Integerdte=#10/12/2017#[10/12/2017], Date[5], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integer[7], Integer[6], Integerdte=#10/12#[10/12/2019], Date[7], Integer[7], Integer[6], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integerdte=#7:08:06 PM#[7:08:06 PM], Date[7], Integer[7], Integer[6], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integerdte=#7:08:06#[7:08:06 AM], Date[7], Integer[7], Integer[6], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integerdte=#19:08:06#[7:08:06 PM], Date[7], Integer[7], Integer[6], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integerdte=#19:08#[7:08:00 PM], Date[7], Integer[7], Integer[6], Integer[5], Integer[4], Integer[3], Integer[2], Integer[1], Integer

Sideway BICK Blog

24/03


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013