- Code:
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
$Form1 = GUICreate("Form1", 299, 53, 192, 124)
$Date1 = GUICtrlCreateDate("2014/01/15", 8, 16, 186, 21)
$Button1 = GUICtrlCreateButton("Button1", 208, 16, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
MsgBox(0,"ทดสอบ",วันนี้-$Date1) ;<---------ตรงนี้เราต้องใส่อย่างไรครับ
EndSwitch
WEnd
4 posters
คำสังไหนที่ใช้สำหรับการนับวัน
xxxautoit- PSsix Member
-
จำนวนข้อความ : 28
ความนิยม : 0
เข้าร่วมเมื่อ : 16/08/2011
- Post n°1
คำสังไหนที่ใช้สำหรับการนับวัน
flapjack- PSsix Member Super Class III
-
จำนวนข้อความ : 314
ความนิยม : 75
เข้าร่วมเมื่อ : 05/10/2010
- Post n°2
Re: คำสังไหนที่ใช้สำหรับการนับวัน
เพิ่มคำสั่ง GUICtrlRead ตามด้านล่างนี้ครับ
- Code:
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
$Form1 = GUICreate("Form1", 299, 53, 192, 124)
$Date1 = GUICtrlCreateDate("2014/01/15", 8, 16, 186, 21)
$Button1 = GUICtrlCreateButton("Button1", 208, 16, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
MsgBox(0,"ทดสอบ",GUICtrlRead($Date1)) ;<---------ตรงนี้เราต้องใส่อย่างไรครับ
EndSwitch
WEnd
xxxautoit- PSsix Member
-
จำนวนข้อความ : 28
ความนิยม : 0
เข้าร่วมเมื่อ : 16/08/2011
- Post n°3
Re: คำสังไหนที่ใช้สำหรับการนับวัน
ใช้สำหรบนับวันครับ ไม่ใช่อ่านค่าของวัน
เช่น วันที่เราเลือก เป็น 1/4/14 แล้วเอาวันนี้ไปลบ เช่น
5/5/14 - 1/4/14 = 35 วัน
แบบนี้อ่ครับ
ขอบคุณครับ
เช่น วันที่เราเลือก เป็น 1/4/14 แล้วเอาวันนี้ไปลบ เช่น
5/5/14 - 1/4/14 = 35 วัน
แบบนี้อ่ครับ
ขอบคุณครับ
torres150533- มือใหม่เพิ่งสมัคร
-
จำนวนข้อความ : 4
ความนิยม : 0
เข้าร่วมเมื่อ : 04/04/2014
- Post n°4
Re: คำสังไหนที่ใช้สำหรับการนับวัน
ถ้าวันครบ ที่เราเซตแล้วมันจะได้อะไรหลอครับ
Arm- PSsix Member Super Class III
-
จำนวนข้อความ : 268
ความนิยม : 54
เข้าร่วมเมื่อ : 31/03/2011
อายุ : 27
- Post n°5
Re: คำสังไหนที่ใช้สำหรับการนับวัน
ประมาณนี้ได้มั้ยครับ (เสียเวลาหา UDF แปลงเวลาตั้งนาน )
- Code:
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
$Form1 = GUICreate("Form1", 299, 53, -1, -1)
$Date1 = GUICtrlCreateDate("2014/01/15", 8, 16, 186, 21, $DTS_SHORTDATEFORMAT)
$Button1 = GUICtrlCreateButton("Button1", 208, 16, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$StartTime = _DateTimeStandard(GUICtrlRead($Date1))
$EndTime = _DateTimeStandard(_NowDate())
MsgBox(0, "ทดสอบ", _DateDiff('D', $StartTime, $EndTime))
EndSwitch
WEnd
Func _DateTimeStandard($sInputDateTime, $fWithSeparators = 1, $sDateFormat = "", $sTimeFormat = "")
Local $sReturnString, $sInputDate, $sInputTime, $sYear, $sMonth, $sDay, $sHour, $sMin, $sSec
Local $sDateSep, $sTimeSep, $sAM, $sPM, $isPM, $sTestDate, $aStringSplit1[9], $aStringSplit2[9]
; Read default system time formats and separators from registry if not provided
If $sDateFormat = "" Then
$sDateFormat = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sShortDate")
$sDateSep = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sDate")
Else
For $A = 1 To StringLen($sDateFormat)
If Not(StringMid($sDateFormat, $A, 1) = "y") And Not(StringMid($sDateFormat, $A, 1) = "m") And Not(StringMid($sDateFormat, $A, 1) = "d") Then
$sDateSep = StringMid($sDateFormat, $A, 1)
ExitLoop
EndIf
Next
EndIf
If $sTimeFormat = "" Then
$sTimeFormat = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sTimeFormat")
$sTimeSep = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sTime")
$sAM = RegRead("HKEY_CURRENT_USER\Control Panel\International", "s1159")
$sPM = RegRead("HKEY_CURRENT_USER\Control Panel\International", "s2359")
Else
For $A = 1 To StringLen($sTimeFormat)
If Not(StringMid($sTimeFormat, $A, 1) = "h") Then
$sTimeSep = StringMid($sTimeFormat, $A, 1)
ExitLoop
EndIf
Next
$sAM = "AM"
$sPM = "PM"
EndIf
; Separate date and time if included (make break at first space)
If StringInStr($sInputDateTime, "T") Then $sInputDateTime = StringReplace($sInputDateTime, "T", " ")
If StringInStr($sInputDateTime, " ") Then
$sInputDate = StringLeft($sInputDateTime, StringInStr($sInputDateTime, " ") - 1)
$sInputTime = StringStripWS(StringReplace($sInputDateTime, $sInputDate, ""), 7)
Else
$sInputDate = $sInputDateTime
$sInputTime = ""
EndIf
; Simple check of input date format (look for separators and unexpected non numeric characters)
$sTestDate = StringReplace($sInputDate, $sDateSep, "")
If StringRegExpReplace($sTestDate, "[0-9]", "") <> "" Then Return SetError(1, 0, "")
If StringInStr($sInputDate, $sDateSep) = 0 And $sDateSep <> "" Then Return SetError(1, 0, "")
If $sInputTime <> "" Then
$sTestDate = StringReplace($sInputTime, $sTimeSep, "")
$sTestDate = StringReplace($sTestDate, $sAM, "")
$sTestDate = StringReplace($sTestDate, $sPM, "")
$sTestDate = StringReplace($sTestDate, " ", "")
If StringRegExpReplace($sTestDate, "[0-9]", "") <> "" Then Return SetError(2, 0, "")
If StringInStr($sInputTime, $sTimeSep) = 0 And $sTimeSep <> "" Then Return SetError(2, 0, "")
EndIf
; Break up date components (using format as a template), unless format is YYYYMMDD
If $sDateFormat = "YYYYMMDD" Then
$sYear = StringMid($sInputDate, 1, 4)
$sMonth = StringMid($sInputDate, 5, 2)
$sDay = StringMid($sInputDate, 7, 2)
Else
$aStringSplit1 = StringSplit($sDateFormat, $sDateSep)
$aStringSplit2 = StringSplit($sInputDate, $sDateSep)
For $A = 1 To $aStringSplit1[0]
If StringInStr($aStringSplit1[$A], "m") Then $sMonth = $aStringSplit2[$A]
If StringInStr($aStringSplit1[$A], "d") Then $sDay = $aStringSplit2[$A]
If StringInStr($aStringSplit1[$A], "y") Then $sYear = $aStringSplit2[$A]
Next
EndIf
; Pad values with 0 if required and fix 2 digit year
If StringLen($sMonth) = 1 Then $sMonth = "0" & $sMonth
If StringLen($sDay) = 1 Then $sDay = "0" & $sDay
If StringLen($sYear) = 2 Then
If $sYear > 70 Then
$sYear = "19" & $sYear
Else
$sYear = "20" & $sYear
EndIf
EndIf
; Break up time components (if given)
If $sInputTime <> "" Then
; Look for AM/PM and note it, then remove from the string
$isPM = 0
If StringInStr($sInputTime, $sAM) Then
$sInputTime = StringReplace($sInputTime, " " & $sAM, "")
$isPM = 1
ElseIf StringInStr($sInputTime, $sPM) Then
$sInputTime = StringReplace($sInputTime, " " & $sPM, "")
$isPM = 2
EndIf
$aStringSplit1 = StringSplit($sTimeFormat, $sTimeSep)
$aStringSplit2 = StringSplit($sInputTime, $sTimeSep)
$sSec = "00"
For $A = 1 To $aStringSplit2[0]
If StringInStr($aStringSplit1[$A], "h") Then $sHour = $aStringSplit2[$A]
If StringInStr($aStringSplit1[$A], "m") Then $sMin = $aStringSplit2[$A]
If StringInStr($aStringSplit1[$A], "s") Then $sSec = $aStringSplit2[$A]
Next
; Clean up time values (change hour to 24h and 0 pad values)
If $isPM = 1 And $sHour = 12 Then $sHour = "00"
If $isPM = 2 And $sHour < 12 Then $sHour = $sHour + 12
If StringLen($sHour) = 1 Then $sHour = "0" & $sHour
If StringLen($sMin) = 1 Then $sMin = "0" & $sMin
If StringLen($sSec) = 1 Then $sSec = "0" & $sSec
$sInputTime = " " & $sHour & ":" & $sMin & ":" & $sSec
EndIf
$sReturnString = $sYear & "/" & $sMonth & "/" & $sDay & $sInputTime
If $fWithSeparators = 0 Then
$sReturnString = StringRegExpReplace($sReturnString, "[^0-9]", "") ; Remove all non-digit characters.
EndIf
Return $sReturnString
EndFunc ;==>_DateTimeStandard
flapjack- PSsix Member Super Class III
-
จำนวนข้อความ : 314
ความนิยม : 75
เข้าร่วมเมื่อ : 05/10/2010
- Post n°6
Re: คำสังไหนที่ใช้สำหรับการนับวัน
xxxautoit พิมพ์ว่า:ใช้สำหรบนับวันครับ ไม่ใช่อ่านค่าของวัน
เช่น วันที่เราเลือก เป็น 1/4/14 แล้วเอาวันนี้ไปลบ เช่น
5/5/14 - 1/4/14 = 35 วัน
แบบนี้อ่ครับ
ขอบคุณครับ
โทษทีครับ (เข้าใจผิด )
ลองโค๊ดล่างนี้ก็ได้ครับ
- Code:
#RequireAdmin
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
$Form1 = GUICreate("Form1", 299, 53, -1, -1)
$Date1 = GUICtrlCreateDate("2014/01/15", 8, 16, 186, 21, $DTS_SHORTDATEFORMAT)
$Button1 = GUICtrlCreateButton("Button1", 208, 16, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$countday = _DateDiff('d', dateFormat(GUICtrlRead($Date1)), _NowCalc() )
MsgBox(0, $countday , $countday )
EndSwitch
WEnd
Func dateFormat($datetaget)
Local $datearray ,$timearray , $formatnewdate
_DateTimeSplit($datetaget, $datearray,$timearray) ; Return Date Array : YYYY [3] , MM [1] , DD[2]
$formatnewdate = $datearray[3]&'/'&$datearray[1]&'/'&$datearray[2]
Return $formatnewdate
EndFunc
xxxautoit- PSsix Member
-
จำนวนข้อความ : 28
ความนิยม : 0
เข้าร่วมเมื่อ : 16/08/2011
- Post n°7
Re: คำสังไหนที่ใช้สำหรับการนับวัน
ได้แล้วครับ
ขอบคุณทุกๆ ข้อมูลที่ให้ครับ
ขอบคุณทุกๆ ข้อมูลที่ให้ครับ
- Code:
#include <Date.au3>
$iDate = _DateDiff('D', "2014/01/01 00:00:00", _NowCalc())
MsgBox(4096, "", "จากปีใหม่ถึงปัจจุบันรวมทั้งสิ้น: " & $iDate &" วัน")
|
|