我有一个我认为是可行的脚本。随机决定尝试第9个月,但失败了。同样在08月份失败。
谷歌搜索,这已经告诉我这是因为Octal Numbers
是我所知道的以8为底的数字。
我不确定如何最好地解决这个问题以满足我的需要,并且可以使用一些建议。
此日期用于通过SCHTASKS
创建任务,该日期需要2位数字的月/日和4位数字的年
当月份使用08和09时,它会不断循环回到开头。我认为这也将适用于这一天。不确定其他数字可能也会受到影响。
:SETDATE
CLS
ECHO.
ECHO Date must be 2 digit Month/Day and 4 digit Year
ECHO.
ECHO.
SET /P SETMONTH=Enter 2 digit month for the restart (01-12):
ECHO.
SET /P SETDAY=Enter 2 digit day for the restart (01-31):
ECHO.
SET /P SETYEAR=Enter 4 digit year for the restart (2019-2025):
IF %SETMONTH% LSS 1 GOTO SETDATE
IF %SETMONTH% GTR 12 GOTO SETDATE
IF %SETDAY% LSS 1 GOTO SETDATE
IF %SETDAY% GTR 31 GOTO SETDATE
IF %SETYEAR% LSS 2019 GOTO SETDATE
IF %SETYEAR% GTR 2025 GOTO SETDATE
答案 0 :(得分:0)
应该考虑发布一种似乎可以满足我的需求的解决方案。它并不能解决所有可能的输入,但确实解决了我的08和09问题。如果有前导0,它将删除前导0,然后它将正常处理。
:SETDATE
CLS
ECHO.
ECHO Date must be 2 digit Month/Day and 4 digit Year
ECHO.
ECHO.
SET /P SETMONTH=Enter 2 digit month (01-12):
ECHO.
SET /P SETDAY=Enter 2 digit day (01-31):
ECHO.
SET /P SETYEAR=Enter 4 digit year (2019-2025):
IF %SETMONTH% == 0 (
SET NEWMONTH=0
) ELSE (
IF "%SETMONTH:~0,1%" == "0" (
SET NEWMONTH=%SETMONTH:~1%
) ELSE (
SET NEWMONTH=%SETMONTH%
)
)
IF %SETDAY% == 0 (
SET NEWDAY=0
) ELSE (
IF "%SETDAY:~0,1%" == "0" (
SET NEWDAY=%SETDAY:~1%
) ELSE (
SET NEWDAY=%SETDAY%
)
)
IF %SETYEAR% == 0 (
SET NEWYEAR=0
) ELSE (
IF "%SETYEAR:~0,1%" == "0" (
SET NEWYEAR=%SETYEAR:~1%
) ELSE (
SET NEWYEAR=%SETYEAR%
)
)
IF %NEWMONTH% LSS 1 GOTO SETDATE
IF %NEWMONTH% GTR 12 GOTO SETDATE
IF %NEWDAY% LSS 1 GOTO SETDATE
IF %NEWDAY% GTR 31 GOTO SETDATE
IF %NEWYEAR% LSS 2019 GOTO SETDATE
IF %NEWYEAR% GTR 2025 GOTO SETDATE
答案 1 :(得分:0)
尽管从技术上讲,这并不是您想要的答案,但我决定将其添加为一个想法。
这是一个独立的批处理文件,旨在提供GUI日历供最终用户选择。它使用PowerShell,据我所知,它应可与Windows 7配合使用,即PowerShell 2.0。
<# :DSel
@Echo Off
Set "_="&For /F Delims^=^ EOL^= %%A In ('PowerShell -NoP -C^
"IEx([IO.File]::ReadAllText('%~f0'))"') Do Set "_=%%A"
If Not Defined _ GoTo DSel
Echo You selected %_%
Pause
Exit /B
#>
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object Windows.Forms.Form
$form.Text = 'Select a date'
$form.Size = New-Object Drawing.Size @(243,230)
$form.StartPosition = 'CenterScreen'
$calendar = New-Object System.Windows.Forms.MonthCalendar
$calendar.ShowTodayCircle = $false
$calendar.MaxDate = ((Get-Date).AddYears(5)).AddDays(-1)
$calendar.MinDate = Get-Date
$calendar.MaxSelectionCount = 1
$form.Controls.Add($calendar)
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(38,165)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(113,165)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Today'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)
$form.ControlBox = $false
$form.Topmost = $true
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$date = $calendar.SelectionStart
Write-Host $($date.ToString('MM-dd-yyyy'))
}
正如您所建议的那样,您已经了解PowerShell,请把它留给您来对PowerShell的东西进行必要的修改。