Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

getDayName()

Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
07-22-2003 23:16
This function gets the name of the day if the date passed to it is valid.
CODE

string getDay(string date) // date must be in the form "mm/dd/yyyy"
{
list datesplit = llParseString2List(date,["/"],[]); //mm/dd/yyyy\
integer month = llList2Integer(datesplit,0);
integer day = llList2Integer(datesplit,1);
integer year = llList2Integer(datesplit,2);
integer a = (14-month)/12;
integer y = year - a;
integer m = month + (12 * a) - 2;

integer returnval = (day + y + (y/4) - (y/100) + (y/400) + ((31*m)/12)) %7;

if(returnval == 0) return "sunday";
if(returnval == 1) return "monday";
if(returnval == 2) return "tuesday";
if(returnval == 3) return "wednesday";
if(returnval == 4) return "thursday";
if(returnval == 5) return "friday";
if(returnval == 6) return "saturday";
else return ""; //invalid date
}



Many thanks to David Trimboli for the 'C' (I think) code (found his site through google).

His site.

If anyone finds any mistakes/optimizations they'd like tom make, feel free to do so :) . I love constructive criticisim.

-Chris

P.S. This also works with leap years :D
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Code Smith
Registered User
Join date: 24 Jun 2003
Posts: 40
07-23-2003 12:11
Cool Chris... Thanks! I can't wait to get home and add this to my timestamp function..... :)
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
07-24-2003 21:43
Cool, put to good use :)

Um... one thing tho :D

Um, me putting this up here means you cant sell it.... without posting the script your using it in yourself... or does that only apply to code written under the GNU private license... :confused: ... I just dont want my stuff sold w/o my perms.
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm