Jump to content
Sign in to follow this  
jbennett

Read date from .ini and add 1 day

Recommended Posts

jbennett

Hi everyone,

Got a quick question.

How can I read a date from an .ini (e.g 31102008) and add 1 day to this date.

Thanks

Regards,

Jon Bennett

Share this post


Link to post
Share on other sites
Juvigy

If i get you right you want to change 31102008 to 01112008 ?

Check FileRead /FileReadLine functions. But you will have to create a complex date checking system as it is easy to change 15102008 with one day but 31102008 and so on is more complicated:).

Share this post


Link to post
Share on other sites
jbennett

Ahhh.

That could be a problem.

In most cases the date will fall on a day other than the last day of the month but in the event that it does land on 31st (or 28 etc) then i'm not sure what to do.

I basically have an .ini file that has the current date and I want it to add 1 day (or 2,3,4,5 depending on what I specify) to this date each time the program is opened.

Cheers

Edited by jbennett

Share this post


Link to post
Share on other sites
DexterMorgan

Ahhh.

That could be a problem.

In most cases the date will fall on a day other than the last day of the month but in the event that it does land on 31st (or 28 etc) then i'm not sure what to do.

I basically have an .ini file that has the current date and I want it to add 1 day (or 2,3,4,5 depending on what I specify) to this date each time the program is opened.

Cheers

well first you should make the date in the INI this

31|10|2008

After that

you can use string split to split it into 3

then you can use

It will look something like this

$date = filereadline($ini,1)
$date_split = stringsplit($date,'|')

if $date_split[1] = '31' then ; if the day is 31 then
if $date_split[2] = '10' then ; if the month is 10 then
$newdate = 1 ; the new date is =1
endif
else
$newdate = $date_split[1] + 1
endif

filewrite($ini,$date_split[1]|' & $date_split[2] & '|' & $date_split[3]);day|month|year

thi probably won't work exactly, you will have to change something, because iM late for school :mellow:

that is a very general idea

Hope it helps


code

Share this post


Link to post
Share on other sites
jbennett

This is what i've got so far. But my brain is so frazzled now that I've forgotten what i'm trying to do lol.

#Include <Date.au3>

;====================================================================================
; $SCHEDULED MSGBOX
;====================================================================================

$Currentday = @WDAY
$scheduled_backup=IniRead(@scriptdir & "\test.ini", "BACKUP", "scheduled_backup","")
if $currentday=$scheduled_backup Then
    $msgbox = msgBox(4, "Scheduled", "It's a scheduled day", 0)
endif


;=============================================
;CALCULATIONS FOR REMINDER
;=============================================
$sys_time=@mday
$next_backup_date=Iniread(@scriptdir & "\test.ini", "BACKUP", "next_backup_schedule","")

if $sys_time<=$next_backup_date then;if sys time smaller than next backup then..
    Exit;exit
Else
EndIf;otherwise msgbox is displayed
msgbox (4096,"Reminder","Backup not run","");msgbox will appear if reminder is due


Iniwrite (@scriptdir & "\test.ini", "BACKUP", "current_day",@WDAY);write current day To
;ini file
$scheduled_backup=IniRead(@scriptdir & "\test.ini", "BACKUP", "scheduled_backup","")
;read the scheduled backup day
$currentday=Iniread (@scriptdir & "\test.ini", "BACKUP", "current_day","")
;read the current day
$calculation=$scheduled_backup-$currentday
;take the scheduled day from the current day
$total=Iniwrite(@scriptdir & "\test.ini", "BACKUP", "total",$calculation)
;write the answer to the total


if $currentday>$scheduled_backup then;if the current day is more than
        Iniread(@scriptdir & "\test.ini", "BACKUP", "next_backup","")
;scheduled day then 
        endif
    _NextBackup();run the next backup


Else;otherwise
    if $currentday<$scheduled_backup then;if the current day is less than the scheduled
;day then move the total to the next_backup day
    $set_total_as_next_backup=Iniread(@scriptdir & "\test.ini", "BACKUP", "total","")
Iniwrite(@scriptdir & "\test.ini", "BACKUP", "next_backup",$set_total_as_next_backup)
_NextBackup();run the next backup

    endif
    
    
;======================================================
; FUNCTION
;======================================================
    
Func _NextBackup()
    
    $next_schedule_day= @mday & @MON & @YEAR
Iniwrite(@scriptdir & "\test.ini", "BACKUP", "next_backup_schedule",$next_schedule_day)
$thisone= Iniread(@scriptdir & "\test.ini", "BACKUP", "next_backup","")
$input=Iniread(@scriptdir & "\test.ini", "BACKUP", "next_backup_schedule","")
$temp = StringRight($input,4) & "/" & StringMid($input,3,2) & "/" & StringLeft($input,2)
MsgBox(0, "", "Converted input date: " & $temp)
$output = _DateAdd('d',$thisone, $temp)
MsgBox(0, "", "Newly calculated date: " & $output & @CRLF & "(Or in case 0, error message: " & @error & " ) ")



$add1 = Iniread(@scriptdir & "\test.ini", "BACKUP", "next_backup","")
$add2 = Iniread(@scriptdir & "\test.ini", "BACKUP", "next_backup_schedule","")
$answer=$add1+$add2
Iniwrite(@scriptdir & "\test.ini", "BACKUP", "next_backup_schedule",$answer)
    

EndFunc

and this is the .ini

[BACKUP]
scheduled_backup=
current_day=
total=
next_backup=
next_backup_schedule=
Edited by jbennett

Share this post


Link to post
Share on other sites
senthor

OK, there's a more simple way.

Save the date like "31.10.2008" or "31|10|2008" or some other splitter.

Then, use

#Include <Date.au3>
$splitstring = "|"
$date = IniRead("config.ini", "Date", "Date", "01" & $splitstring & "01" & $splitstring & "1970")
$date = StringSplit($date, $splitstring)
If $date[0] < 3 Then
    Msgbox(0,"Error", "Date not correctly entered.")
    Exit
EndIf
$newDate = $date[3] & "/" & $date[2] & "/" & $date[1] & " 00:00:00"
$newDate = _DateAdd("D", 1, $newDate)
$newDate = StringReplace($newDate, " 00:00:00", "")
$newDate = StringSplit($newDate, "/")
If $date[0] < 3 Then
    Msgbox(0,"Error", "Internal error.")
    Exit
EndIf
$newDate = $newDate[3] & $splitstring & $newDate[2] & $splitstring & $newDate[1]
Msgbox(0,"",$newDate)oÝ÷ Øò¢çhmÁ©í¶¬y«)+mz»¬y«­¢+Ø%¹±Õ±ÐíѹÔÌÐì(ÀÌØíѵÀô%¹¥I ÅÕ½Ðí½¹¥¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíÑÅÕ½Ðì°ÅÕ½ÐíÑÅÕ½Ðì°ÅÕ½ÐìÀÄÀÄÄäÜÀÅÕ½Ðì¤(ÀÌØíѵÀôMÑÉ¥¹MÁ±¥Ð ÀÌØíѵÀ°ÅÕ½ÐìÅÕ½Ðì¤)%ÀÌØíѵÁlÁt±ÐìàQ¡¸(%5ͽà À°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½Ðí]ɽ¹Ñ¥µ½ÉµÐ¸ÅÕ½Ðì¤(%á¥Ð)¹%)¥´ÀÌØíÑlÑtôlÌ°ÀÌØíѵÁlÅtµÀìÀÌØíѵÁlÉt°ÀÌØíѵÁlÍtµÀìÀÌØíѵÁlÑt°ÀÌØíѵÁlÕtµÀìÀÌØíѵÁlÙtµÀìÀÌØíѵÁlÝtµÀìÀÌØíѵÁláut(ÀÌØí¹ÝÑôÀÌØíÑlÍtµÀìÅÕ½Ðì¼ÅÕ½ÐìµÀìÀÌØíÑlÉtµÀìÅÕ½Ðì¼ÅÕ½ÐìµÀìÀÌØíÑlÅtµÀìÅÕ½ÐìÀÀèÀÀèÀÀÅÕ½Ðì(ÀÌØí¹ÝÑô}Ñ ÅÕ½ÐíÅÕ½Ðì°Ä°ÀÌØí¹ÝѤ(ÀÌØí¹ÝÑôMÑÉ¥¹IÁ± ÀÌØí¹ÝÑ°ÅÕ½ÐìÀÀèÀÀèÀÀÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØí¹ÝÑôMÑÉ¥¹MÁ±¥Ð ÀÌØí¹ÝÑ°ÅÕ½Ðì¼ÅÕ½Ðì¤)%ÀÌØíÑlÁt±ÐìÌQ¡¸(%5ͽà À°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½Ðí%¹Ñɹ°ÉɽȸÅÕ½Ðì¤(%á¥Ð)¹%(ÀÌØí¹ÝÑôÀÌØí¹ÝÑlÍtµÀìÀÌØí¹ÝÑlÉtµÀìÀÌØí¹ÝÑlÅt)5ͽà À°ÅÕ½ÐìÅÕ½Ðì°ÀÌØí¹ÝѤ
Edited by senthor

Share this post


Link to post
Share on other sites
jbennett

But the problem I have is that the code is suppose to check if it's not a scheduled day and then run a reminder.

If the reminder has already been run then it wont run again until the next scheduled date.

If the next scheduled date is missed then it will run the reminder again.

I've just tried so hard to get it to work but just can't seem to do it :-(

Share this post


Link to post
Share on other sites
senthor

look here

or my way:

If @MDAY = 1 and not fileexists(@appdatadir & "\GLi\ModManager\updated.temp") Then
    update(0)
    dim $UPDFile = FileOpen(@appdatadir & "\GLi\ModManager\updated.temp", 1)
    FileClose($UPDFile)
ElseIf @MDAY <> 1 and fileexists(@appdatadir & "\GLi\ModManager\updated.temp") Then
    FileDelete(@appdatadir & "\GLi\ModManager\updated.temp")
EndIF
Edited by senthor

Share this post


Link to post
Share on other sites
jbennett

What if you run the code on a day that's not 1 and then the week after you also run the code on a day that's not 1?

ElseIf @MDAY <>

Thanks

Share this post


Link to post
Share on other sites
PsaltyDS

Hi everyone,

Got a quick question.

How can I read a date from an .ini (e.g 31102008) and add 1 day to this date.

Thanks

Regards,

Jon Bennett

I couldn't really tell if you thought this first question was answered, so:

AutoIt (and Windows too) has many formats for date/time strings. The specific one to use depends on circumstances. Inside AutoIT the easiest to work with is "YYYY/MM/DD hh:mm:ss", which comes from using for example _NowCalc() instead of just _Now(). If you must use that other format, it can be accommodated, but you'll make your life easier if you use the standard format that works with AutoIt's date calculation functions like _DateAdd() and _DateDiff().

If that date string was "2008/10/31" then the function would just be:

$sTomorrow = _DateAdd("D", 1, "2008/10/31")

:mellow:

P.S. Or, of course, you could convert on the fly:

#include <Date.au3>

$sDate = "31102008"
$sDateCalc = StringRight($sDate, 4) & "/" & StringMid($sDate, 3, 2) & "/" & StringLeft($sDate, 2)
$sNextDay = _DateAdd("D", 1, $sDateCalc)
ConsoleWrite("$sNextDay = " & $sNextDay & @LF)

:(

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
jbennett

Thanks Psalty.

This is basically another attempt at getting things working haha. Been trying for days now without luck.

I like your idea but feel that there is some questions regarding the code.

I just hope I get this fixed soon as my head is really hurting.

Cheers

Share this post


Link to post
Share on other sites
jbennett

EDIT: I've solved the problem now :-)

Hi everyone..

I really like the following code:

#include <Date.au3>

$input = "31102008"

$temp = StringRight($input,4) & "/" & StringMid($input,3,2) & "/" & StringLeft($input,2)
MsgBox(0, "", "Converted input date: " & $temp)

$output = _DateAdd('d', 1, $temp)

MsgBox(0, "", "Newly calculated date: " & $output & @CRLF & "(Or in case 0, error message: " & @error & " ) ")

I'm currently using this to get the date from an .ini file. The problem i've got is that the date in the .ini file is already in the correct format and all I want to do is add 1 to do the date. (the 1 bit will be in the .ini file so this could be any number but just trying to keep things simple at the moment).

Does anyone know how this could be modified to achieve this. The reason I want to keep the code is because it's quite useful if the day in the .ini is the last day of the month as it recognizes to move the month number up by 1.

thanks

Edited by jbennett

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  

×