Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Day of week from Date?

Mike Zidane
Registered User
Join date: 10 Apr 2004
Posts: 255
09-22-2004 10:57
Anyone know how to figure out the day of the week from the date? ie, if I use llgettimestamp to get the date... how do I know if today is wednesday?
Francis Chung
This sentence no verb.
Join date: 22 Sep 2003
Posts: 918
09-22-2004 11:18
I figured this out once. I forget the exact algorithm, and I'm not in-world right now to go fetch it.

I sell some wrist-watches, the source code for which I've tagged GPL. Grab a landmark from my profile picks to find a copy :)
_____________________
--
~If you lived here, you would be home by now~
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
09-22-2004 11:27
why not use this:

string strDate = llGetDate();

see that here llGetDate

That page also has a link to llGetTimeStamp()

If you wanted to use the llGetTimeStamp() function, then use a string parsing command to get the first 10 characters from the string produced by the llGetTimeStamp().

string strDate = string result = llGetSubString(llGetTimeStamp(), 0, 9);

(I think that should work)... only don't try that in the global definitions area, it might not work there.
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
MSo Lambert
Registered User
Join date: 16 Aug 2004
Posts: 101
09-22-2004 11:57
Samhain, I believe Mike wants to know the day of the week (like today is wednesday), not the current date.

I couldn't find the Francis' GPLed code, but I've been using this function (algorithm based on Zeller's congruence):
CODE

// Returns the day of week for the given day, month and year
// Day 1 is Sunday, 7 is Saturday
// Author: MSo Lambert
// Free to use and modify
integer DayOfWeek(integer day, integer month, integer year)
{
integer century;
integer i;

month = month - 2;
if (month < 1)
{
month = month + 12;
year = year - 1;
}

century = year / 100;
year = year - century * 100;
i = (260 * month - 15) / 100 + day + year + year / 4 + century / 4 - century - century;

if (i < 0)
{
i = i + 7;
}

i = i - i / 7 * 7 + 1;
return i;
}


Example usage:
CODE
// Constants
list DAYS_OF_WEEK = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"];
...

llWhisper(0, "9/22/2004 was " + llList2String(DAYS_OF_WEEK, DayOfWeek(22, 9, 2004) - 1));
_____________________
MSo
Mike Zidane
Registered User
Join date: 10 Apr 2004
Posts: 255
09-22-2004 12:41
Thankyasir, I do belive that'll do it :)
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
09-23-2004 11:27
Oops! I must have been sleepy reading that. Somehow I knew my answer was too easy! =)
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts