Asked — Edited

Future Date

Is there a way via scripting for me to get the day name out of a future date. For example I want the robot to say that September 9 is Friday instead of September 9. I can get it to work for today, but am looking for a way to do it for future dates.

Thanks for any suggestions.


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

PRO
Synthiam
#1  

There's a way to do anything with programming:)

Do this...


$theDate = cdatetime("03-04-2016")

# Get format from https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

$theMonth = fmtdate($theDate, "MMMM")
$theDay = fmtdate($theDate, "dd")
$theDayWord = fmtdate($theDate, "dddd")

say($theMonth + " " + $theDay + " is a " + $theDayWord)

Or shortened is...


$theDate = cdatetime("03-04-2016")

# Get format from https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

say(fmtdate($theDate, "MMMM") + " " + fmtdate($theDate, "dd") + " is a " + fmtdate($theDate, "dddd"))

PRO
USA
#2  

If you want to go hardcore:)

a good exercise for a bored kid at home.


#############
# Constants #
#############
 
DefineArray($t, 12, 0)
#$t[0]=0
$t[1]=3
$t[2]=2
$t[3]=5
#$t[4]=0
$t[5]=3
$t[6]=5
$t[7]=1
$t[8]=4
$t[9]=6
$t[10]=2
$t[11]=4

DefineArray($dayWords, 7)
$dayWords[0]="Sunday"
$dayWords[1]="Monday"
$dayWords[2]="Tuesday"
$dayWords[3]="Wednesday"
$dayWords[4]="Thursday"
$dayWords[5]="Friday"
$dayWords[6]="Saturday"

######################################################################
# Expected Parameters:                                               #
#                      $theYear, $theMonth, $theDay                  #
# Returned Parameters:                                               # 
#                      $theWeekDay (0=Sunday..6=Saturday)            #
#                      $theWeekDayWord                               #
######################################################################

$theYear=2000
$theMonth=9
$theDay=5

######################################################################
# https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week #
######################################################################

$y=$theYear
if ($theMonth<3)
  $y=$y-1
endif
$theWeekDay=($y+$y/4-$y/100+$y/400+$t[$theMonth-1]+$theDay)%7
$theWeekDayWord=$dayWords[$theWeekDay]

#debug
say("Year " + $theYear + " month " + $theMonth + " day " + $theDay + " is a " + $theWeekDayWord)

PRO
USA
#3  

Thanks to both of you. I had been working on the hardcore version and it just seemed there should be an easier way. Amazing how DJ got it down to one line. Just amazing.

Thanks so much.