Sign in to follow this  
Followers 0
camilla

time manupilation problem

12 posts in this topic

#1 ·  Posted (edited)

hello everybody, i need your help please it a simple script , i want to run a message box in the next day from this day.

example:

- i took the current day as refernce

- add one day to it

-make a condition to see if it is the new day

- if it is true run a message box

this is my code nee some help

 

#include <Date.au3>
#include <MsgBoxConstants.au3>
; Add 1 days to today
$sDate = @YEAR & "/" & @MON & "/" & @MDAY ; the current date;
$sNewDate = _DateAdd('d', 1, $sDate); we add one day to the current day;
Sleep(2000);we wait for 2 seconds
While 1
If $sDate = $sNewDate Then ; condition to check if the current date equals our newDate
Sleep(5000)
    MsgBox($MB_SYSTEMMODAL, "", "Today + 1 days:" & $sNewDate); if the condition is true then message popup
EndIf
WEnd

 

thank you in advance

there is one small problem which is the CPU when i run my code it is 100/100 need to low it

Edited by camilla

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You aren't updating your $sDate, so it will always be yesterday.

While 1
    If @YEAR & "/" & @MON & "/" & @MDAY = $sNewDate Then ; condition to check if the current date equals our newDate
        MsgBox($MB_SYSTEMMODAL, "", "Today + 1 days:" & $sNewDate); if the condition is true then message popup
    EndIf
    Sleep(5000)
 WEnd
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

How about this idea?  It's something to work from.

#include <MsgBoxConstants.au3>

#include <Date.au3>

Global $current_mday = @MDAY

Do
  If $current_mday <> @MDAY Then ; condition to check if the current date equals our newDate
    $current_mday = @MDAY
    MsgBox($MB_SYSTEMMODAL, "", "Today + 1 days: " & _DateAdd('d', 1, @YEAR & "/" & @MON & "/" & @MDAY)) ; if the condition is true then message popup
  EndIf
Until False

Edit: code addition

Every time I change my computer's date by one day the msgbox pops up.

Edited by jaberwacky

Share this post


Link to post
Share on other sites

thank you for replay

i like your solution is there any idea about the burning CPU

you use the result in the message box i need it to be true  by means

when i put my script in startup folder exactly after one day from it's execution  the message appears

Share this post


Link to post
Share on other sites

yes, but as i said the result of new day after appears in the message  box you use @MDAY and add one day to it in the message box

look at my script

take current day

add one day to it

if it is the new day

message box appears

it may add more than one day

and it may not just open message box also you can run ccleaner  have you got the idea

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The best way would be to schedule a task for the $sNewDate.

The scheduled task cmd can be a one-liner, like:

consolewrite(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"')

note: grab the output of the consolewrite for the actual task command.

That would use 0 cpu/ram

Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

 

jdelaney

The best way would be to schedule a task for the $sNewDate.

The scheduled task cmd can be a one-liner, like:

@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"'

That would use 0 cpu/ram

 

yes i agree with you, but schedule a task always have problem in the different OS windows7/windows8

Share this post


Link to post
Share on other sites

 

:*  thank you very much for your help i appreciate it, me too don't want  complete solution just need to help others who may be in my case

Share this post


Link to post
Share on other sites

camilla,

Is your goal to run CCleaner once per day, just after midnight?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

....

there is one small problem which is the CPU when i run my code it is 100/100 need to low it

camilla,

Addressing the high usage of the CPU problem only.

Note jdelaney's script of post #2 - The sleep function is outside of the If...Then...EndIf function, but inside of the While...Wend loop (where it is supposed to be). This is the correct placement of the Sleep function.

Your script of post #1 has the Sleep function, but it is inside of the If...EndIf which is only accessed when the If statement is true.   

Notice jaberwacky's script of post #3. This script, when run, causes a higher than necessary CPU usage because of the absence of a Sleep function within the Do...Until loop.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Realm
      By Realm
      After Several Minutes searching the forums for a simple solution to calculating for the Unix Time, as required for another project I am working on, I was astonished to not find one clean and universal solution. After looking over the helpfile, I noticed one simple solution given in the example with _DateDiff(). However it did not account for my current timezone or daylight savings time.
      Without further ado... This is my example of Calculating for a current Unix Time stamp or  seconds since Jan, 1st, 1970 00:00:00 GMT.
      This function will account for your timezone as well as for daylight savings time.
      Update: v0.3
      -Added Function to revert a Unix Time stamp into Date form.
      -Added parameter to original _GetUnixTime() allowing for a custom date since Jan 1st 1970 to be passed and converted to Unix Time.
      #include <Date.au3> #include <Array.au3> #include <Constants.au3> Local $iUnixTime1 = _GetUnixTime() MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds Since Jan, 1st, 1970 00:00:00 GMT" & @CRLF & $iUnixTime1) Local $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp in Local Time" & @CRLF & $sUnixDate1) $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1, False) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp with $iReturnLocal = False which returns UTC Time" & @CRLF & $sUnixDate1) Local $iUnixTime2 = _GetUnixTime('2013/01/01 00:00:00') MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds since 2013/01/01 00:00:00" & @CRLF & $iUnixTime2) ; Get timestamp for input datetime (or current datetime). Func _GetUnixTime($sDate = 0);Date Format: 2013/01/01 00:00:00 ~ Year/Mo/Da Hr:Mi:Se Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $utcTime = "" If Not $sDate Then $sDate = _NowCalc() If Int(StringLeft($sDate, 4)) < 1970 Then Return "" If $aSysTimeInfo[0] = 2 Then ; if daylight saving time is active $utcTime = _DateAdd('n', $aSysTimeInfo[1] + $aSysTimeInfo[7], $sDate) ; account for time zone and daylight saving time Else $utcTime = _DateAdd('n', $aSysTimeInfo[1], $sDate) ; account for time zone EndIf Return _DateDiff('s', "1970/01/01 00:00:00", $utcTime) EndFunc ;==>_GetUnixTime ;$blTrim: Year in short format and no seconds. Func _GetDate_fromUnixTime($iUnixTime, $iReturnLocal = True) Local $aRet = 0, $aDate = 0 Local $aMonthNumberAbbrev[13] = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] Local $timeAdj = 0 If Not $iReturnLocal Then Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $timeAdj = $aSysTimeInfo[1] * 60 If $aSysTimeInfo[0] = 2 Then $timeAdj += $aSysTimeInfo[7] * 60 EndIf $aRet = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $iUnixTime + $timeAdj ) If @error Or Not $aRet[0] Then Return "" $aDate = StringSplit(StringTrimRight($aRet[0], 1), " ", 2) Return $aDate[4] & "/" & StringFormat("%.2d", _ArraySearch($aMonthNumberAbbrev, $aDate[1])) & "/" & $aDate[2] & " " & $aDate[3] EndFunc ;==>_GetUnixDate Enjoy!
      Realm
      Update: >Added some functionality and a suggestion from FireFox
    • Simpel
      By Simpel
      Hi, I created a gui with date field but formatted as time in HH:mm. It always shows "now-time". Even if I try to set it with GUICtrlSetData.
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm" ; Just display hours and minutes <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUICtrlSetData($idDate, "00:00") ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example How can I set the time field with another time and how can this field be set blank?
      Regards, Conrad
    • MyEarth
      By MyEarth
      Hi guys
      I need to get time of different city, London, Jerusalem, Mosca and many others. My starting script:
      #include <Date.au3> Local $iUTC, $iHour, $iMinute, $iSecond $iUTC = _Date_Time_GetSystemTime() $iHour = DllStructGetData($iUTC, "Hour") $iMinute = DllStructGetData($iUTC, "Minute") $iSecond = DllStructGetData($iUTC, "Second") ConsoleWrite("+UTC: " & $iHour & ":" & $iMinute & ":" & $iSecond & @CRLF) My idea was start from UTC time and then add-remove hours. But what about the DST, Daylight Savings Time? How i can know if in a country is active or not? There is an API? Example with _Date_Time_GetTimeZoneInformation it will give the current time zone settings and not for other time zone. I don't have understand if is possible or not 
      On the help i have found SystemTimeToTzSpecificLocalTime but i don't have understand how to use for other time zone...
      Thanks
    • ur
      By ur
      To get the current time stamp, I got the below code.
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #RequireAdmin ; Under Vista the Windows API "SetSystemTime" may be rejected due to system security $td = _Date_Time_GetSystemTime() $td = _Date_Time_SystemTimeToDateTimeStr($td) $td = StringReplace($td, " ", "_") $td = StringReplace($td, ":", "_") MsgBox(0,"",$td) But it is not giving the date or time of the timezone where the system is there.
      Please suggestt
    • Simpel
      By Simpel
      Hi,
      I wanted to use _GetLogonTime() by guinness (https://www.autoitscript.com/forum/topic/19370-autoit-wrappers/?do=findComment&comment=942069).
      #include <Date.au3> #include <Array.au3> ConsoleWrite(_GetLogonTime() & @LF) Func _GetLogonTime($sUserName = @UserName, $sComputerName = @ComputerName) ; Idea by trancexx: http://www.autoitscript.com/forum/topic/113611-if-isadmin-not-detected-as-admin/ Local $aRet = DllCall("netapi32.dll", "long", "NetUserGetInfo", "wstr", $sComputerName, "wstr", $sUserName, "dword", 11, "ptr*", 0) _ArrayDisplay($aRet) If @error Or $aRet[0] Then Return SetError(1, 0, False) Local $sHours = DllStructGetData(DllStructCreate("ptr;ptr;ptr;ptr;dword;dword;dword;ptr;ptr;dword;dword;dword;dword;ptr;dword;ptr;dword;dword;byte;dword", $aRet[4]), 18) DllCall("netapi32.dll", "long", "NetApiBufferFree", "ptr", $aRet[4]) Return _DateAdd("h", "-" & $sHours, _NowCalc()) EndFunc ;==>_GetLogonTime It always returns false.
      I displayed $aRet:
      [0]|2221
      [1]|mycomputer
      [2]|myuser
      [3]|11
      [4]|0x0000000000000000
      $aRet[4] shouldn't be 0x0000000000000000 right? Any help?
      Regards, Conrad