Sign in to follow this  
Followers 0
Existance

Advanced Date Script

9 posts in this topic

Hi all,

I'm an AutoIt and scripting newbie...so be nice :D

I currently use AutoIt to launch jscripts that launch URLs or link to file with dates in the name. What i am doing is launching URLs with mp3 or mms clips that are updated daily, and have the date as part of their filename. I then record the audio stream using AutoIt or jscripts controlling the programs etc.

My issue is that while i can get the date layouts i want in jscript i can't seem to do it properly in AutoIt. And having AutoIt lauch jscripts was fine as a workaround but stupid long term.

With jscript i have the date in a seperate DD+MM+YY format i can change around depending on my needs.

So one website will be DDMMYY and another will be YYMMDD or MM-DD-YY.mp3 or MMDDYYYY etc.

Harder than this is that i need to be able to call the date from "X" days ago AND from the last "tuesday" or "defined day" from within the last 7 days.

Heres a "defined day" jscript i use:

function getDateOfLastWeekday(weekday){

var date=new Date() // Get current date

var difference=0 // Set the difference between the date we want and today

if(date.getDay()<weekday){ // Has the desired weekday passed?

difference=7-(weekday-date.getDay()) // Yes, figure out how many days ago that that weekday occurred.

}

else{

difference=date.getDay()-weekday // No, figure out in how many days it will occur.

}

new_date=new Date(date.getTime()-difference*86400000) // Make a new date by removing 86400000 milliseconds for each day from today's date.

new_year=new_date.getYear().toString().substring() // Get the year, convert to string and remove first two numbers

new_month=new String((new_date.getMonth()+1)) // Get the month, convert to string

if(new_month.length==1){new_month="0"+new_month} // Prepend a 0 if neccessary

new_day=new_date.getDate().toString() // Get the day, convert to string

if(new_day.length==1){new_day="0"+new_day} // Prepend a 0 if neccessary

return new_year+new_month+new_day // Smack it all together in one big string and send it back to whoever asked!

}

var Shell = new ActiveXObject("WScript.Shell");

Shell.Run("mms://somesite.com/file"+getDateOfLastWeekday(6)+".wmv");

// It takes an integer between 0 and 6 as an argument (above 6 is accepted but might give incorrect results).

// 0 is Sunday, 1 is Monday, ..., and 6 is Saturday.

// It returns the date of the previous weekday that matches the argument in the form of ddmmyy.

// So you could do:

// Shell.Run("mms://somewebsite/"+getDateOfLastWeekday(3)+".wmv");

// to always get the .wmv file from last Wednesday, or today if it's Wednesday.

Can anyone give me a hand with getting all that to work in an au3 script? I have tried to do it with Autoit but am struggling. Like i said i am a bit of a newbie to scripting and Autoit so i would really appreciate a hand.

Thanks guys.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This answers the first part of what you're looking for... More info can be found in help file under "Macro Reference", "Time and Date Macros".

MsgBox ( 0, "DDMMYY", @MDAY & @MON & StringRight (@Year, 2 ) )
MsgBox ( 0, "YYMMDD ", StringRight (@Year, 2 ) & @MDAY & @MON )
MsgBox ( 0, "MM-DD-YY", @MON & "-" & @MDAY & "-" & StringRight (@Year, 2 ) )
MsgBox ( 0, "MMDDYYYY ", @MON & @MDAY & @Year )

And I don't quite understand the below, could you elaborate a little bit?

Harder than this is that i need to be able to call the date from "X" days ago AND from the last "tuesday" or "defined day" from within the last 7 days.

Edited by exodius

Share this post


Link to post
Share on other sites

Hi,

This might help, could be improved but i think its on the right track of what your after.

#include <Date.au3>
$ddmmyy = @MDAY & @MON & StringRight(@YEAR, 2) ;style of date in DDMMYY format
$yymmdd = StringRight(@YEAR, 2) & @MON & @MDAY ;style of date in YYMMDD format
$mm_yy_dd = @MON & "-" & @MDAY & "-" & StringRight(@YEAR, 2) ;style of date in MM-YY-DD format
$x_day = "-4" ;the number of days you would like to subtract from the current day
$xDate = _DateAdd('d', $x_day , _NowCalc()) ;subtracts the number of days given in the VAR $x_day
$defineddate = 'Tuesday' ;the day in long format that you would like the date given for within the past week e.g 'Tuesday' , 'Friday' etc
$vardate = _NowCalcDate() ;VAR used in the loop below, this sets the initial value to the current date

;a loop that will subtract a day, each time returning the name of the new subtracted date which will continue
; until $definedate = $vardate, this only works for a week and does not include the current day e.g today is friday and the $definedate
; is equal to 'Friday' it will go back 7 days to the previous Friday

Do
    $vardate = _DateAdd('d', -1 , $vardate)
    $datesplitted = StringSplit($vardate, "/", 0)
    $vardatenumber = _DateToDayOfWeek($datesplitted[1], $datesplitted[2], $datesplitted[3])
    $vardateday = _DateDayOfWeek($vardatenumber)
Until $defineddate = $vardateday

;Msgboxes displaying the date styles

MsgBox(64, "Date Styles", "Three different date styles specified in the variables:" & @CRLF & $ddmmyy & @CRLF & $yymmdd & @CRLF & $mm_yy_dd)

MsgBox(64, "Date Style checking for the day name", $vardateday & " was on the " & $datesplitted[3] & "/" & $datesplitted[2] & "/" & $datesplitted[1])

MsgBox(64, "Today -X number of days", "Today " & $x_day & " days : " & $xDate)

Sorry if its a bit messy, quickly tested it at work and seems to be along the lines of what i think you were after.

Cheers :D

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,

To more directly replicate your script;

;weekday.au3 0_2
#Include <date.au3>
MsgBox(0,"","normal order short(0 or blank) Mon1="&_GetDateOfLastWeekday(1))    ;0 short style if you wish to emulate javascript numbers?
MsgBox(0,"","Int order short(1)Tues2'.'="&_GetDateOfLastWeekday(2,'.',1 ))  ;1 short style
MsgBox(0,"","USA order short(2) Wed3'/' ="&_GetDateOfLastWeekday(3,'/',2))  ;2 short style
MsgBox(0,"","normal order long(3)Sat6'-'="&_GetDateOfLastWeekday(6,'-',3))  ;3 long style
MsgBox(0,"","normal order long(3) Thurs4''="&_GetDateOfLastWeekday(4,'' ,3))    ;3 long style
MsgBox(0,"","Int order long(4)Sun7''="&_GetDateOfLastWeekday(7,'',4))   ;4 long style
MsgBox(0,"","USA order long(5)Fri5'@'="&_GetDateOfLastWeekday(5,'@',5)) ;5 style
func _GetDateOfLastWeekday($i_weekday,$s_Separator="",$i_Type=0)
    $i_weekday+=1 ; if you wish to emulate javascript numbers?
    $ar_DateNow=StringSplit(_NowDate() ,"/");// Get current date ; to array
    $i_nowday=_DateToDayOfWeek ( $ar_DateNow[3], $ar_DateNow[2], $ar_DateNow[1] )
    $s_DateNormal=_DateAdd ( 'd',$i_weekday-$i_nowday, _NowCalcDate());_Date($s_CurrentDate.getTime()-$s_difference*86400000) ;// Make a new date by removing 86400000 milliseconds for each day from today's date.
    $ar_DateNew=StringSplit($s_DateNormal ,"/");// Get new date ; to array
    if $i_Type=0 then $s_Datereturn= StringReplace(Stringmid($s_DateNormal,3),"/",$s_Separator) ; normal order short
    if $i_Type=3 then $s_Datereturn= StringReplace($s_DateNormal,"/",$s_Separator); normal order long
    if $i_Type=1 then $s_Datereturn= StringReplace($ar_DateNew[3]&"/"&$ar_DateNew[2]&"/"&stringright($ar_DateNew[1],2),"/",$s_Separator) ; Int order short
    if $i_Type=2 then $s_Datereturn= StringReplace($ar_DateNew[2]&"/"&$ar_DateNew[3]&"/"&stringright($ar_DateNew[1],2),"/",$s_Separator) ; USA order short
    if $i_Type=4 then $s_Datereturn= StringReplace($ar_DateNew[3]&"/"&$ar_DateNew[2]&"/"&$ar_DateNew[1],"/",$s_Separator) ; Int order long
    if $i_Type=5 then $s_Datereturn= StringReplace($ar_DateNew[2]&"/"&$ar_DateNew[3]&"/"&$ar_DateNew[1],"/",$s_Separator) ; USA order long
    return $s_Datereturn
EndFunc   ;==>_GetDateOfLastWeekday
Best, Randall Edited by randallc

Share this post


Link to post
Share on other sites

Hi,

Sorry about taking so long to reply. I got pretty busy and had a lot of other things come up i had to do before i had the time to test out the solutions.

These suggestions are along the lines of what i was looking for but i am still having trouble getting them to work in my situation. My biggest problem is that i am still pretty new to AutoIT and have trouble understanding even the basic parts of the code and what functions they do plus syntax etc.

I tried Randallc solution and got the error:

Error:

Si_weekday+=1 ; if you wish to emulate javascript numbers?

$i_weekday^ERROR

Error: Expected a "=" operator in assignment statement.

Maybe i was supposed to add in something or modify something first...im not sure. Like i said i am not familiar enough with the AutoIT code to know what is wrong. I'm pretty sure its me, not the code.

I tried fu2m8 sollution and it is pretty close to what i want. I feel stupid asking...but how would i make it launch a URL with the calculated date in a format i choose as part of the URL? Would i do something like this:

RunWait(@COMSPEC & " /c start http://www.somesite.com/file_"$datesplitted[3]".mp3")

But the above doesn't work.

What i need is to be able to use that date format in a command to launch a url or other. Combos i need will be:

RunWait(@COMSPEC & " /c start http://www.somesite.com/file_[date of last tuesday].mp3")

RunWait(@COMSPEC & " /c start http://www.somesite.com/file_[date of last any other day].mp3")

Date format needs to be adjustable so i can choose formats like DDMMYY, MMDDYY, MM-DD-YY, YYYYMMDD in the above [date of last xxxxxx] field.

Thanks for all your help guys,

Existance

Share this post


Link to post
Share on other sites

These suggestions are along the lines of what i was looking for but i am still having trouble getting them to work in my situation. My biggest problem is that i am still pretty new to AutoIT and have trouble understanding even the basic parts of the code and what functions they do plus syntax etc.

Maybe you should start with a basic understanding?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

HI,

Si_weekday+=1 ; if you wish to emulate javascript numbers?

needs beta.

Otherwise you have to write Si_weekday= weekday +1

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

I will download the latest beta, have a play in the next couple of days and see where i end up from there. At least i know why it wasn't working now.

Thanks again for everyones help ;-)

Existance

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