dateValue

dateValue関数は、日付形式の文字列をシリアル値に変換する関数です。

構文
dateValue( str )
引数
str必須
日付文字列。yyyy/mm/dd、dd/mm/yyyy、yyyy年mm月dd日、yyyy年mm月、ge年mm月dd日、mm/dd、mm月dd日
戻り値
シリアル値

プログラム

UWSC
//////////////////////////////////////////////////
// 【引数】
//   str : 日付文字列。yyyy/mm/dd、dd/mm/yyyy、yyyy年mm月dd日、yyyy年mm月、ge年mm月dd日、mm/dd、mm月dd日 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION dateValue(str)
HASHTBL Pattern
Pattern["year"] = "(190[0-9]|19[1-9][0-9]|[2-9][0-9]{3})"
Pattern["month"] = "(1[0-2]|0?[1-9]|Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)"
Pattern["day"] = "([1-2][0-9]|3[0-1]|0?[1-9])"
SELECT TRUE
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
Matches = reExecute(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
WITH Matches.Item(0)
IFB reTest(.SubMatches(1), "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?")
DIM array[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
IF LENGTH(.SubMatches(1)) = 3 THEN arrayMap("COPY(%val%, 1, 3)", array)
m = arraySearch(.SubMatches(1), array) + 1
ELSE
m = .SubMatches(1)
ENDIF
date = .SubMatches(2) + "/" + text(m, "00") + "/" + .SubMatches(0)
ENDWITH
CASE reTest(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + .SubMatches(1) + "/01"
ENDWITH
CASE reTest(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
y = VAL(.SubMatches(1))
SELECT .SubMatches(0)
CASE "M"; y = y + 1867
CASE "T"; y = y + 1911
CASE "S"; y = y + 1925
CASE "H"; y = y + 1988
CASE "R"; y = y + 2018
SELEND
date = y + "/" + .SubMatches(2) + "/" + .SubMatches(3)
ENDWITH
CASE reTest(str, Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["month"] + "/" + Pattern["day"])
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
CASE reTest(str, Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["month"] + "月" + Pattern["day"] + "日")
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
SELEND
RESULT = uwscToSerial(GETTIME(0, date))
FEND
//////////////////////////////////////////////////
// 【引数】
//   callback : 配列の各要素に適用するコールバック関数 
//   array : コールバック関数を適用する配列。参照引数。 
// 【戻値】
//   callback関数を適用した後、 適用後の要素を含む配列 
//////////////////////////////////////////////////
PROCEDURE arrayMap(callback, var array[])
DIM tmp[RESIZE(array)]
DIM n = 0
FOR %val% IN array
tmp[n] = EVAL(callback)
n = n + 1
NEXT
RESIZE(array, RESIZE(tmp))
FOR n = 0 TO RESIZE(tmp)
array[n] = tmp[n]
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   needle : 検索する値 
//   haystack : 配列 
// 【戻値】
//   needleが見つかった場合に配列のキー 
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
DIM i = 0
FOR item IN haystack
IFB item = needle THEN
RESULT = i
EXIT
ENDIF
i = i + 1
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻値】
//   日時(date)に、指定した単位(interval)の時間(num)を加算して返します 
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
IF time <> "00:00:00" THEN d = d + " " + time
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた時間間隔を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   arr : 最大公約数を求める数値を格納した配列 
// 【戻値】
//   最大公約数 
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス m 月とする 
// 【戻値】
//   date から m 月後の月末の日付 
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : (”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
// 【戻値】
//   曜日 (0:日曜…、6:土曜) 
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = INT(serial * 24) MOD 24
FEND
//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : YYYYMMDD 
// 【戻値】
//   TRUE : 日付として認識できる、FALSE : 日付として認識できない 
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE	
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str <> "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator <> 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK 
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift	// 分子
DIM denominator = shift		// 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
//   array : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
//////////////////////////////////////////////////
// 【引数】
//   uwscTime : UWSC時間 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION uwscToSerial(uwscTime)
uwscDate = uwscTime / 86400
RESULT = 36526 + uwscDate
FEND

シリアル値

シリアル値とは1900年1月1日を1とし、その日からの通算日数と時刻を表す値のことです。1日毎に1ずつ増え、小数部分が時刻を表します。

日付

  1. 1900年1月1日1
  2. 1900年1月2日2
  3. 1900年1月3日3
  4. 2000年1月1日36526
  5. 2020年1月1日43831

時刻

シリアル値で時刻は小数部分で表されます。

1日で「1」増えるので、1時間は1/24で「0.41666666…」、1分は1/1440で「0.00069444444…」、1秒は1/86400で「0.0000115740740…」増えることになります。

時刻「hh:nn:ss」のシリアル値は以下の式で求めることができます。

24時間=86400秒。時分秒を秒単位に直して86400で割る。

1時間=3600秒、1分=60秒。

\[ \frac{hh \times 3600 + nn \times 60 + ss}{86400} \]
  1. 0:0:00.0
  2. 3:0:00.125
  3. 6:0:00.0.25
  4. 12:0:00.5
  5. 21:0:00.875
  6. 23:59:590.0999988425925926
  7. 24:0:00.0

プログラム実行例

写真の撮影日時毎に枚数を取得

選択したフォルダにある写真の撮影日時を取得・カウントします。

UWSC
DIM Shell = CREATEOLEOBJ("Shell.Application")
Folder = Shell.BrowseForFolder(0, "フォルダを選択してください。", 0)
HASHTBL iColumn
FOR i = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
HASHTBL dates
FOR i = 0 TO Folder.Items.Count - 1	
FUKIDASI(i + "/" + Folder.Items.Count)
DIM FolderItem = Folder.Items.Item(i)
DIM datetime = Folder.GetDetailsOf(FolderItem, iColumn["撮影日時"])
IFB datetime = "" THEN
dates["0000/00/00"] = dates["0000/00/00"] + 1
ELSE
deleteControlCharacter(datetime)
DIM date = text(datevalue(datetime), "yyyy/mm/dd")
dates[date] = dates[date] + 1
ENDIF
NEXT
FOR i = 0 TO LENGTH(dates) - 1
PRINT dates[i, HASH_KEY] + "<#TAB>" + dates[i, HASH_VAL]
NEXT
// 制御文字を削除する
FUNCTION deleteControlCharacter(Var str)
DIM array[] = CHR(8206), CHR(8207)
FOR item IN array
str = REPLACE(str, item, "")
NEXT
RESULT = str
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻値】
//   日時(date)に、指定した単位(interval)の時間(num)を加算して返します 
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
IF time <> "00:00:00" THEN d = d + " " + time
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた時間間隔を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   arr : 最大公約数を求める数値を格納した配列 
// 【戻値】
//   最大公約数 
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス m 月とする 
// 【戻値】
//   date から m 月後の月末の日付 
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : (”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
// 【戻値】
//   曜日 (0:日曜…、6:土曜) 
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = INT(serial * 24) MOD 24
FEND
//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : YYYYMMDD 
// 【戻値】
//   TRUE : 日付として認識できる、FALSE : 日付として認識できない 
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE	
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str <> "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator <> 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK 
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift	// 分子
DIM denominator = shift		// 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
//   array : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
    (1) (2) (12,13,14)
  1. Shell.Folder.Items.Count(12,13)
  2. (13)
  3. Shell.Folder.Items.Item(14)
  4. (15) (20) (20) (25)
結果
プレーンテキスト
2021/05/29	2
2021/06/01	2
2021/06/02	5
2021/06/03	2
2021/06/04	16
0000/00/00	6

Windowsの稼働時間を取得

UWSC
HASHTBL INFO
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM filename = uniqueFilename(FSO.BuildPath(GET_CUR_DIR, "SYSTEMINFO.csv"))
FID = FOPEN(filename, F_READ OR F_WRITE)
FPUT(FID, DOSCMD("systeminfo /FO CSV"))
FCLOSE(FID)
FID = FOPEN(filename, F_READ OR F_WRITE)
FOR col = 0 TO 33
INFO[FGET(FID, 1, col)] = FGET(FID, 2, col)
NEXT
FCLOSE(FID)
FSO.DeleteFile(filename)
DIM startupTime = INFO["システム起動時間"]
date1 = dateValue(startupTime) + timeValue(startupTime)
date2 = uwscToSerial(GETTIME())
PRINT INT(date2 - date1) + ":" + text(date2 - date1, "hh:mm:ss")
//////////////////////////////////////////////////
// 【引数】
//   callback : 配列の各要素に適用するコールバック関数 
//   array : コールバック関数を適用する配列。参照引数。 
// 【戻値】
//   callback関数を適用した後、 適用後の要素を含む配列 
//////////////////////////////////////////////////
PROCEDURE arrayMap(callback, var array[])
DIM tmp[RESIZE(array)]
DIM n = 0
FOR %val% IN array
tmp[n] = EVAL(callback)
n = n + 1
NEXT
RESIZE(array, RESIZE(tmp))
FOR n = 0 TO RESIZE(tmp)
array[n] = tmp[n]
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   needle : 検索する値 
//   haystack : 配列 
// 【戻値】
//   needleが見つかった場合に配列のキー 
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
DIM i = 0
FOR item IN haystack
IFB item = needle THEN
RESULT = i
EXIT
ENDIF
i = i + 1
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻値】
//   日時(date)に、指定した単位(interval)の時間(num)を加算して返します 
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
IF time <> "00:00:00" THEN d = d + " " + time
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた時間間隔を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 日付文字列。yyyy/mm/dd、dd/mm/yyyy、yyyy年mm月dd日、yyyy年mm月、ge年mm月dd日、mm/dd、mm月dd日 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION dateValue(str)
HASHTBL Pattern
Pattern["year"] = "(190[0-9]|19[1-9][0-9]|[2-9][0-9]{3})"
Pattern["month"] = "(1[0-2]|0?[1-9]|Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)"
Pattern["day"] = "([1-2][0-9]|3[0-1]|0?[1-9])"
SELECT TRUE
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
Matches = reExecute(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
WITH Matches.Item(0)
IFB reTest(.SubMatches(1), "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?")
DIM array[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
IF LENGTH(.SubMatches(1)) = 3 THEN arrayMap("COPY(%val%, 1, 3)", array)
m = arraySearch(.SubMatches(1), array) + 1
ELSE
m = .SubMatches(1)
ENDIF
date = .SubMatches(2) + "/" + text(m, "00") + "/" + .SubMatches(0)
ENDWITH
CASE reTest(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + .SubMatches(1) + "/01"
ENDWITH
CASE reTest(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
y = VAL(.SubMatches(1))
SELECT .SubMatches(0)
CASE "M"; y = y + 1867
CASE "T"; y = y + 1911
CASE "S"; y = y + 1925
CASE "H"; y = y + 1988
CASE "R"; y = y + 2018
SELEND
date = y + "/" + .SubMatches(2) + "/" + .SubMatches(3)
ENDWITH
CASE reTest(str, Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["month"] + "/" + Pattern["day"])
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
CASE reTest(str, Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["month"] + "月" + Pattern["day"] + "日")
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
SELEND
RESULT = uwscToSerial(GETTIME(0, date))
FEND
//////////////////////////////////////////////////
// 【引数】
//   arr : 最大公約数を求める数値を格納した配列 
// 【戻値】
//   最大公約数 
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス m 月とする 
// 【戻値】
//   date から m 月後の月末の日付 
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : (”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
// 【戻値】
//   曜日 (0:日曜…、6:土曜) 
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = INT(serial * 24) MOD 24
FEND
//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : YYYYMMDD 
// 【戻値】
//   TRUE : 日付として認識できる、FALSE : 日付として認識できない 
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE	
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str <> "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator <> 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK 
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift	// 分子
DIM denominator = shift		// 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 時刻文字列。hh:nn:ss AM/PM、hh:nn AM/PM、hh AM/PM、hh:nn:ss、hh:nn、hh時nn分ss秒、hh時nn分のいずれかの形式を指定。 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
DIM serial = 0
DIM Matches
DIM pattern = "(\d+)"
DIM hh = "(0?[0-9]|1[0-2])"
DIM ampm = "([AP]M|[ap]m)"
SELECT TRUE
CASE reTest(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(3)) + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(2)) + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + hh + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + " " + ampm + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0) MOD 12) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)
serial = serial / 24
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
DEFAULT
serial = ERR_VALUE
SELEND
RESULT = serial - INT(serial)
FEND
//////////////////////////////////////////////////
// 【引数】
//   array : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
//////////////////////////////////////////////////
// 【引数】
//   path : ファイルのパス 
// 【戻値】
//   重複しないファイル名 
//////////////////////////////////////////////////
FUNCTION uniqueFilename(path)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB FSO.FileExists(path) THEN
DIM fol = FSO.GetParentFolderName(path)
DIM filename = FSO.GetBaseName(path)
DIM extension = FSO.GetExtensionName(path)
DIM i = 2
WHILE FSO.FileExists(FSO.BuildPath(fol, filename + " (" + i + ")." + extension))
i = i + 1
WEND
RESULT = FSO.BuildPath(fol, filename + " (" + i + ")." + extension)
ELSE
RESULT = path
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   uwscTime : UWSC時間 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION uwscToSerial(uwscTime)
uwscDate = uwscTime / 86400
RESULT = 36526 + uwscDate
FEND
//////////////////////////////////////////////////
// 【引数】
//   num : 符号を調べる数値 
// 【戻値】
//    : 正の数 
//   1、 : 0 
//   0、 : 負の数 
//   -1、 : 
//////////////////////////////////////////////////
FUNCTION sign(num)
SELECT TRUE
CASE num > 0
RESULT = 1
CASE num = 0
RESULT = 0
CASE num < 0
RESULT = -1
SELEND
FEND
    (3) (5) (6,10) (7) (7) (8) (12) (16) (19) (19) (20) (21)
結果
プレーンテキスト
0:08:16:46
解説
  1. 1行目
    UWSC
    HASHTBL INFO
    連想配列INFOを宣言します。
  2. 3行目
    UWSC
    DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
    FileSystemObjectオブジェクトを生成し、 FSO に代入します。
  3. 5行目
    UWSC
    DIM filename = uniqueFilename(FSO.BuildPath(GET_CUR_DIR, "SYSTEMINFO.csv"))
    カレントディレクトリに「SYSTEMINFO.csv」というファイル名でCSVファイルを作成する。
  4. 6行目
    UWSC
    FID = FOPEN(filename, F_READ OR F_WRITE)
    「SYSTEMINFO.csv」を読み込み/書き込みモードで開く。
  5. 7行目
    UWSC
    FPUT(FID, DOSCMD("systeminfo /FO CSV"))
    コマンドプロンプトで「systeminfo /FO CSV」を実行し、その結果をファイルに書き込む。
  6. 8行目
    UWSC
    FCLOSE(FID)
    CSVファイルを閉じる。
  7. 10行目
    UWSC
    FID = FOPEN(filename, F_READ OR F_WRITE)
    「SYSTEMINFO.csv」を読み込み/書き込みモードで開く。
  8. 11-13行目
    UWSC
    FOR col = 0 TO 33	INFO[FGET(FID, 1, col)] = FGET(FID, 2, col)NEXT
    1行目に項目、2行目に値が書かれているので、INFO[項目]に値を格納する。
  9. 14行目
    UWSC
    FCLOSE(FID)
    CSVファイルを閉じる。
  10. 16行目
    UWSC
    FSO.DeleteFile(filename)
    CSVファイルを削除する。
  11. 18行目
    UWSC
    DIM startupTime = INFO["システム起動時間"]
    「システム起動時間」をstartupTimeに代入する。
  12. 19行目
    UWSC
    date1 = dateValue(startupTime) + timeValue(startupTime)
    時間を小数表記にする。
  13. 20行目
    UWSC
    date2 = uwscToSerial(GETTIME())
    UWSC時間をシリアル時間に変換する。
  14. 21行目
    UWSC
    PRINT INT(date2 - date1) + ":" + text(date2 - date1, "hh:mm:ss")
    小数表記から時間表記にする。

日付が指定した範囲内にあるか

今日の日付が「2022/04/01〜2022/04/05」の範囲内にあるか。

日付をシリアル値に変換し、「2022/04/01以降」かつ「2022/04/05以前」かを調べる。

UWSC
IFB dateValue("2022/04/01") <= dateValue(today()) AND dateValue(today()) <= dateValue("2022/04/05") THEN
PRINT "範囲内です"
ELSE
PRINT "範囲外です"
ENDIF
//////////////////////////////////////////////////
// 【引数】
//   callback : 配列の各要素に適用するコールバック関数 
//   array : コールバック関数を適用する配列。参照引数。 
// 【戻値】
//   callback関数を適用した後、 適用後の要素を含む配列 
//////////////////////////////////////////////////
PROCEDURE arrayMap(callback, var array[])
DIM tmp[RESIZE(array)]
DIM n = 0
FOR %val% IN array
tmp[n] = EVAL(callback)
n = n + 1
NEXT
RESIZE(array, RESIZE(tmp))
FOR n = 0 TO RESIZE(tmp)
array[n] = tmp[n]
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   needle : 検索する値 
//   haystack : 配列 
// 【戻値】
//   needleが見つかった場合に配列のキー 
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
DIM i = 0
FOR item IN haystack
IFB item = needle THEN
RESULT = i
EXIT
ENDIF
i = i + 1
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻値】
//   日時(date)に、指定した単位(interval)の時間(num)を加算して返します 
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
IF time <> "00:00:00" THEN d = d + " " + time
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた時間間隔を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 日付文字列。yyyy/mm/dd、dd/mm/yyyy、yyyy年mm月dd日、yyyy年mm月、ge年mm月dd日、mm/dd、mm月dd日 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION dateValue(str)
HASHTBL Pattern
Pattern["year"] = "(190[0-9]|19[1-9][0-9]|[2-9][0-9]{3})"
Pattern["month"] = "(1[0-2]|0?[1-9]|Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)"
Pattern["day"] = "([1-2][0-9]|3[0-1]|0?[1-9])"
SELECT TRUE
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
Matches = reExecute(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
WITH Matches.Item(0)
IFB reTest(.SubMatches(1), "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?")
DIM array[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
IF LENGTH(.SubMatches(1)) = 3 THEN arrayMap("COPY(%val%, 1, 3)", array)
m = arraySearch(.SubMatches(1), array) + 1
ELSE
m = .SubMatches(1)
ENDIF
date = .SubMatches(2) + "/" + text(m, "00") + "/" + .SubMatches(0)
ENDWITH
CASE reTest(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + .SubMatches(1) + "/01"
ENDWITH
CASE reTest(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
y = VAL(.SubMatches(1))
SELECT .SubMatches(0)
CASE "M"; y = y + 1867
CASE "T"; y = y + 1911
CASE "S"; y = y + 1925
CASE "H"; y = y + 1988
CASE "R"; y = y + 2018
SELEND
date = y + "/" + .SubMatches(2) + "/" + .SubMatches(3)
ENDWITH
CASE reTest(str, Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["month"] + "/" + Pattern["day"])
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
CASE reTest(str, Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["month"] + "月" + Pattern["day"] + "日")
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
SELEND
RESULT = uwscToSerial(GETTIME(0, date))
FEND
//////////////////////////////////////////////////
// 【引数】
//   arr : 最大公約数を求める数値を格納した配列 
// 【戻値】
//   最大公約数 
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス m 月とする 
// 【戻値】
//   date から m 月後の月末の日付 
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : (”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
// 【戻値】
//   曜日 (0:日曜…、6:土曜) 
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = INT(serial * 24) MOD 24
FEND
//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : YYYYMMDD 
// 【戻値】
//   TRUE : 日付として認識できる、FALSE : 日付として認識できない 
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE	
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str <> "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator <> 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK 
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift	// 分子
DIM denominator = shift		// 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
//   
// 【戻値】
//   今日の日付 
//////////////////////////////////////////////////
FUNCTION today()
GETTIME()
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   array : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
//////////////////////////////////////////////////
// 【引数】
//   uwscTime : UWSC時間 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION uwscToSerial(uwscTime)
uwscDate = uwscTime / 86400
RESULT = 36526 + uwscDate
FEND
    (1)

フォルダ内のファイルを更新日時でソートする

UWSC
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("C:\Program Files (x86)\UWSC")
DIM FolderItems = Folder.Items
HASHTBL iColumn
FOR i = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
DIM filename[-1]
DIM datetime[-1]
FOR i = 0 TO FolderItems.Count - 1
DIM FolderItem = FolderItems.Item(i)
IF FolderItem.isFolder THEN CONTINUE
arrayPush(filename, Folder.GetDetailsOf(FolderItem,iColumn["名前"]))
arrayPush(datetime, Folder.GetDetailsOf(FolderItem, iColumn["更新日時"]))
NEXT
QSORT(datetime, QSRT_NATURALA, filename)
FOR i = 0 TO UBound(filename)
PRINT filename[i] + "<#TAB>" + datetime[i]
NEXT
//////////////////////////////////////////////////
// 【引数】
//   array : 要素を追加する配列(参照引数) 
//   str : 追加する要素 
// 【戻値】
//   処理後の配列の中の要素の数 
//////////////////////////////////////////////////
FUNCTION arrayPush(var arr[], str)
DIM res = RESIZE(arr, UBound(arr) + 1)
arr[res] = str
RESULT = res + 1
FEND
//////////////////////////////////////////////////
// 【引数】
//   array : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
    (1) (2) (3) (8,18,19) (15) (16) (17) (21) (21) (24) (26)
結果
プレーンテキスト
UDebug.chm	2014/05/11 1:58
RecIE.chm	2014/05/11 1:58
Uws2Exe.chm	2015/08/13 16:12
RecUws.dll	2016/03/25 4:57
UWSC.exe	2016/10/15 13:33
Uws2Exe.exe	2016/10/15 13:34
RecIE.exe	2016/10/15 13:35
UDebug.exe	2016/10/15 13:37
XRef.exe	2016/10/15 13:38
Readme.txt	2016/10/15 13:39
uwsc.chm	2016/10/15 13:41
unins000.exe	2018/06/27 12:48
unins000.dat	2018/06/27 12:49

写真を撮影日時毎にフォルダ分けする

UWSC
CONST ssfMYPICTURES = 39
DIM Folder[1]
DIM folderspec[1]
DIM Shell = CREATEOLEOBJ("Shell.Application")
folderspec[0] = "D:\Pictures\100ANDRO\"
Folder[0] = Shell.NameSpace(folderspec[0])
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
HASHTBL iColumn
FOR i = 0 TO 350
iColumn[Folder[0].GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
DIM destination[-1]
DIM path[-1]
DIM cnt = Folder[0].Items.Count - 1
FOR i = cnt TO 0 STEP -1
FUKIDASI(i + "/" + cnt)
DIM FolderItem = Folder[0].Items.Item(i)
IF FolderItem.isFolder THEN CONTINUE
DIM filename = FolderItem.Name
DIM datetime = deleteControlCharacter(Folder[0].GetDetailsOf(FolderItem, iColumn["撮影日時"]))
PRINT filename
PRINT datetime
PRINT "-----"
TRY
DIM date = text(dateValue(datetime), "yyyy-mm-dd")
EXCEPT
date = "0000-00-00"
ENDTRY
folderspec[1] = FSO.BuildPath(folderspec[0], date)
Folder[1] = Shell.NameSpace(folderspec[1])
arrayPush(destination, folderspec[1])
arrayPush(path, FolderItem.Path)
NEXT
FOR i = 0 TO UBound(destination)
IF !FSO.FolderExists(destination[i]) THEN CreateFolders(destination[i])
Folders = Shell.NameSpace(destination[i])
Folders.MoveHere(path[i])
NEXT
FUNCTION deleteControlCharacter(str)
DIM array[] = CHR(8206), CHR(8207)
FOR item IN array
str = REPLACE(str, item, "")
NEXT
RESULT = str
FEND
//////////////////////////////////////////////////
// 【引数】
//   callback : 配列の各要素に適用するコールバック関数 
//   array : コールバック関数を適用する配列。参照引数。 
// 【戻値】
//   callback関数を適用した後、 適用後の要素を含む配列 
//////////////////////////////////////////////////
PROCEDURE arrayMap(callback, var array[])
DIM tmp[RESIZE(array)]
DIM n = 0
FOR %val% IN array
tmp[n] = EVAL(callback)
n = n + 1
NEXT
RESIZE(array, RESIZE(tmp))
FOR n = 0 TO RESIZE(tmp)
array[n] = tmp[n]
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   array : 要素を追加する配列(参照引数) 
//   str : 追加する要素 
// 【戻値】
//   処理後の配列の中の要素の数 
//////////////////////////////////////////////////
FUNCTION arrayPush(var arr[], str)
DIM res = RESIZE(arr, UBound(arr) + 1)
arr[res] = str
RESULT = res + 1
FEND
//////////////////////////////////////////////////
// 【引数】
//   needle : 検索する値 
//   haystack : 配列 
// 【戻値】
//   needleが見つかった場合に配列のキー 
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
DIM i = 0
FOR item IN haystack
IFB item = needle THEN
RESULT = i
EXIT
ENDIF
i = i + 1
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   folderspec : 作成するフォルダのパス 
// 【戻値】
//   
//////////////////////////////////////////////////
PROCEDURE CreateFolders(folderspec)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
folderspec = FSO.GetAbsolutePathName(folderspec)
IF !FSO.DriveExists(FSO.GetDriveName(folderspec)) THEN EXIT
DIM parentPath = FSO.GetParentFolderName(folderspec)
IFB !FSO.FolderExists(parentPath) THEN
CreateFolders(parentPath)
ENDIF
IF !FSO.FolderExists(folderspec) THEN FSO.CreateFolder(folderspec)
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻値】
//   日時(date)に、指定した単位(interval)の時間(num)を加算して返します 
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
IF time <> "00:00:00" THEN d = d + " " + time
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた時間間隔を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 日付文字列。yyyy/mm/dd、dd/mm/yyyy、yyyy年mm月dd日、yyyy年mm月、ge年mm月dd日、mm/dd、mm月dd日 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION dateValue(str)
HASHTBL Pattern
Pattern["year"] = "(190[0-9]|19[1-9][0-9]|[2-9][0-9]{3})"
Pattern["month"] = "(1[0-2]|0?[1-9]|Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)"
Pattern["day"] = "([1-2][0-9]|3[0-1]|0?[1-9])"
SELECT TRUE
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
Matches = reExecute(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
WITH Matches.Item(0)
IFB reTest(.SubMatches(1), "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?")
DIM array[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
IF LENGTH(.SubMatches(1)) = 3 THEN arrayMap("COPY(%val%, 1, 3)", array)
m = arraySearch(.SubMatches(1), array) + 1
ELSE
m = .SubMatches(1)
ENDIF
date = .SubMatches(2) + "/" + text(m, "00") + "/" + .SubMatches(0)
ENDWITH
CASE reTest(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + .SubMatches(1) + "/01"
ENDWITH
CASE reTest(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
y = VAL(.SubMatches(1))
SELECT .SubMatches(0)
CASE "M"; y = y + 1867
CASE "T"; y = y + 1911
CASE "S"; y = y + 1925
CASE "H"; y = y + 1988
CASE "R"; y = y + 2018
SELEND
date = y + "/" + .SubMatches(2) + "/" + .SubMatches(3)
ENDWITH
CASE reTest(str, Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["month"] + "/" + Pattern["day"])
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
CASE reTest(str, Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["month"] + "月" + Pattern["day"] + "日")
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
SELEND
RESULT = uwscToSerial(GETTIME(0, date))
FEND
//////////////////////////////////////////////////
// 【引数】
//   arr : 最大公約数を求める数値を格納した配列 
// 【戻値】
//   最大公約数 
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス m 月とする 
// 【戻値】
//   date から m 月後の月末の日付 
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : (”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
// 【戻値】
//   曜日 (0:日曜…、6:土曜) 
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = INT(serial * 24) MOD 24
FEND
//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : YYYYMMDD 
// 【戻値】
//   TRUE : 日付として認識できる、FALSE : 日付として認識できない 
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE	
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str <> "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator <> 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK 
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift	// 分子
DIM denominator = shift		// 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
//   array : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
//////////////////////////////////////////////////
// 【引数】
//   uwscTime : UWSC時間 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION uwscToSerial(uwscTime)
uwscDate = uwscTime / 86400
RESULT = 36526 + uwscDate
FEND
    (6,10) (8,38,46) (15,27) (21) (21) (24) (25) (26) (27) (33) (33) (37) (40,41) (41) (44)
  1. FSO.FolderExists(45)
  2. (45) (47)

関連記事

now (自作関数)
現在の日時の シリアル値 を返します。
dateSerial (自作関数)
引数に指定した年、月、日の日付が表すシリアル値を返します。
getSerialTime (自作関数)
UWSC時間 から シリアル値 を取得します。
uwscToSerial (自作関数)
UWSC時間 を シリアル値 に変換します。
serialToUwsc (自作関数)
シリアル値 を UWSC時間 に変換します。
serialToUNIX (自作関数)
シリアル値 を UNIX時間 に変換します。
UNIXToSerial (自作関数)
UNIX時間 を シリアル値 に変換します。
Hour (自作関数)
シリアル値 から「時」を求めます。
Minute (自作関数)
シリアル値 から「分」を求めます。
Second (自作関数)
シリアル値 から「秒」を求めます。
getWeekdayName (自作関数)
GETTIMEで取得した曜日の番号を指定したフォーマットで返します。
getYear (自作関数)
指定された日付の「年」を返します。
getMonth (自作関数)
指定された日付の「月」を返します。
getDay (自作関数)
指定された日付の「日」を返します。
getWeekday (自作関数)
引数に指定された日付の曜日番号(0:日曜〜6:土曜)を返します。
timeValue (自作関数)
指定した時間の シリアル値 を求める。
GETTIME (スクリプト関数)
日付、時間を取得します。
isDate (自作関数)
引数に指定した値が日付として認識できる場合はTrueを返します。認識できない場合はFalseを返します。
getEndOfMonth (自作関数)
[var]date[/var]で指定された月の月末日を取得します。
today (自作関数)
今日の日付を返します。
dateString (自作関数)
指定された日付を西暦から 和暦 に変換します。
YMDToJD (自作関数)
グレゴリオ暦 を ユリウス日 に変換します。
JDToYMD (自作関数)
ユリウス日 を グレゴリオ暦 に変換します。
dateAdd (自作関数)
日時に、指定した単位の時間を加算して返します。
dateDiff (自作関数)
指定された2つの日付の時間間隔を返します。
getNthWeekday (自作関数)
指定年月の第何何曜日(第nW曜日)の日付を返します。
getRokuyo (自作関数)
西暦から 六曜 を求めます。
getKyureki (自作関数)
西暦から 旧暦 を求めます。