チケット #45238

get yesterday and 2 days back date (datestr - today)

登録: 2022-07-26 16:46 最終更新: 2022-08-03 22:03

報告者:
担当者:
(未割り当て)
チケットの種類:
状況:
完了
コンポーネント:
(未割り当て)
マイルストーン:
(未割り当て)
優先度:
5 - 中
重要度:
5 - 中
解決法:
なし
ファイル:
なし
投票
点数: 0
No votes
0.0% (0/0)
0.0% (0/0)

詳細

Hello,

is there a way to request the yesterday date in teraterm?

we want to send a command 'A date <yesterday 00:00:00>,<now>'

we are able to get today 00:00:00 using datestr. And so the date for today, but we wish to set the start time to yesterday.

Any idea?

StartTime = datestr
EndTime = datestr
strconcat StartTime ' 00:00:00'
strconcat EndTime ' '
strconcat EndTime timestr

pause 3
;send all data from 00:00 to enddate for today
;sendln 'A date StartTime,EndTime'
;sendln StartTime
;sendln EndTime
Command = 'A date '
strconcat Command StartTime
strconcat Command ','
strconcat Command EndTime
sendln Command
;sendln 'A date 2021-11-16 00:00:00,2021-11-17 12:30:00'
pause 3
sendln 'End Command Quit'

チケットの履歴 (5 件中 3 件表示)

2022-07-26 16:46 更新者: reneo_mudron
  • 新しいチケット "get yesterday and 2 days back date (datestr - today)" が作成されました
2022-07-26 18:50 更新者: nmaya
  • 詳細が更新されました
コメント

Split the start date string, and calc year, month and day of yesterday, and concat them.

2022-08-03 00:53 更新者: reneo_mudron
コメント

Resolution:

i got a very ugly and not scalable resolution, because it looks to me that i am not able to use logical and / or conditions within the if then else endif condition. But it works:

;Starttime is yesterday 00:00:00
;Endtime is now
;we need to set one day back for getdate = parse - set back - strconcat
GetDate DayString "%#d"
GetDate MonthString "%#m"
GetDate YearString "%Y"

;converting string to integer and distracting 1 day
str2int Day DayString
Day = Day - 1
int2str DayString Day

;if day-1 in previuos month we need distract Month-1
if day=0 then
 str2int Month MonthString
 Month = Month - 1
 ;Month = 0
 int2str MonthString Month
endif

;Get String for month in format 01-12 and distract year if shifted (Month 0-11)
str2int Month MonthString
if Month = 0 then
  MonthString = '12'
  str2int Year YearString
  Year = Year - 1
  int2str YearString Year
 elseif Month < 10 then
   Trailing = '0'
   strconcat Trailing MonthString
   MonthString = Trailing
   ;dispstr MonthString 
 else
  dispstr 'Month is OK: '
  dispstr MonthString 
endif

;set up end day to get the corrent end of month
Run = Day

;while Run=0
if Month = 0 then 
  EndDay = '31'
 elseif Month = 1 then 
  EndDay = '31'
 elseif Month = 2 then 
  EndDay = '28' 
 elseif Month = 3 then 
  EndDay = '31'
 elseif Month = 4 then 
  EndDay = '30' 
 elseif Month = 5 then 
  EndDay = '31'
 elseif Month = 6 then 
  EndDay = '30' 
 elseif Month = 7 then 
  EndDay = '31'
 elseif Month = 8 then 
  EndDay = '31'
 elseif Month = 9 then 
  EndDay = '30' 
 elseif Month = 10 then 
  EndDay = '31'
 else EndDay = '30'
endif
; Run=Run+1
;endwhile

dispstr 'End Day is: '
dispstr EndDay 
pause 4

if Day=0 then 
    DayString=EndDay
    dispstr 'Previous month and day is:'
    dispstr DayString
    StartTime = YearString
    strconcat StartTime '-'
    strconcat StartTime MonthString
    strconcat StartTime '-'
    strconcat StartTime DayString 
 elseif Day<10 then
  Trailing = '0'
  strconcat Trailing DayString
  Daystring = Trailing
  dispstr 'Day string added 0: '  
  dispstr DayString
  StartTime = YearString
  strconcat StartTime '-'
  strconcat StartTime MonthString
  strconcat StartTime '-'
  strconcat StartTime DayString
 else 
  dispstr 'Day is OK: '
  dispstr DayString
  StartTime = YearString
  strconcat StartTime '-'
  strconcat StartTime MonthString
  strconcat StartTime '-'
  strconcat StartTime DayString
endif

EndTime = datestr
strconcat EndTime ' '
strconcat EndTime timestr
;StartTime = datestr
strconcat StartTime ' 00:00:00'

;print to command line the start and end times
dispstr 'End Time is: '
dispstr EndTime
dispstr 'Start Time is: '
dispstr StartTime
pause 3

;open log file in append mode read/write
;fileopen fhandle filename appendFlag [ReadOnlyFlag] 0 optional
fileopen file Filename 1 

pause 1
;send all data from 00:00 to enddate for today
;sendln 'A date StartTime,EndTime'
;sendln StartTime
;sendln EndTime
Command = 'A date '
strconcat Command StartTime
strconcat Command ','
strconcat Command EndTime
sendln Command
;sendln 'A date 2021-11-16 00:00:00,2021-11-17 12:30:00'
pause 3
sendln 'End Command Quit'
(編集済, 2022-08-03 21:56 更新者: nmaya)
2022-08-03 00:54 更新者: reneo_mudron
  • 状況オープン から 完了 に更新されました
2022-08-03 22:03 更新者: nmaya
コメント

another solution:

; get y, m, d as integer from 'YYYY-MM-DD'
getdate tmp
strsplit tmp '-'
str2int y groupmatchstr1
str2int m groupmatchstr2
str2int d groupmatchstr3

; calc yesterday
if d == 1 then
  if m == 1 then
    y = y - 1
    m = 12
  else
    m = m - 1
  endif
  if m == 4 || m == 6 || m == 9 || m == 11 then
    d = 30
  elseif m == 2 then
    if y % 400 == 0 then
      d = 29
    elseif y % 100 != 0 && y % 4 == 0 then
      d = 29
    else
      d = 28
    endif
  else
    d = 31
  endif
else
  d = d - 1
endif

; output
sprintf2 yesterday '%02d-%02d-%02d' y m d
messagebox yesterday 'yesterday'

添付ファイルリスト

添付ファイルはありません

編集

ログインしていません。ログインしていない状態では、コメントに記載者の記録が残りません。 » ログインする