Blockland Forums > Modification Help
getFullDateTime() - returns MM/DD/YYYY hh:mm:ss
(1/3) > >>
Xalos:
getDateTime() only returns two year digits, meaning it will not work if you happen to be a time traveller from 1920 or 2120.

If you need the full year, this is the function you need.


--- Code: ---// returns the date and time, with the full current year
function getFullDateTime()
{
// get the current date and time from getDateTime
%value = getDateTime();
%date = getWord(%value, 0);

// if the date has changed, or the date has never been set, get the current century by creating a temporary file
if ($CurrDate $= "" || $CurrDate !$= %date)
{
$CurrDate = %date;
%file = new FileObject();
%file.openForWrite("base/temp/temp.txt");
%file.close();
%file.delete();
$CurrCentury = getSubStr(getFileModifiedSortTime("base/temp/temp.txt"), 0, 2) + 19;
fileDelete("base/temp/temp.txt");
}

// replace the year in the date with the full year
%date = strReplace(%date, "/", " ");
%date = setWord(%date, 2, $CurrCentury * 100 + getWord(%date, 2));

// return the full date and time
return strReplace(%date, " ", "/") SPC getWord(%value,1);
}
--- End code ---

Known issues:
Does not work if the current year is before 1900. If you're time travelling from 1899 or before, you're out of luck.
Does not work if the function is called on the same day of the year, 100 years apart.
Does not work if the file base/temp/temp.txt exists, is read-only, and has a last modified date in a different century.
exit:
someone in the future is gonna see this thread and go "jesus, imagine using dates"
DurkaDude:
Thank god for this. Now I can distinguish between all my data saved in 1919 and 2019.
PhantOS:
xalos:
time travelers:
Swollow:
this was always my go to solution

--- Code: ---function getRealYear() //xd
{
%datetime = getDateTime();
%day = getSubStr(%datetime,3,2);
if($swol_currDayRealYearCheck $= "" || $swol_currDayRealYearCheck !$= %day)
{
$swol_currDayRealYearCheck = %day;
%z = (((getUTC()/86400)|0)+719468)|0;
%era = ((%z>=0?%z:%z-146096)/146097)|0;
%doe = ((%z-%era*146097))|0;
%yoe = ((%doe-(%doe/1460|0)+(%doe/36524|0)-(%doe/146096|0))/365)|0;
%y = (%yoe+%era*400)|0;
%comp = getSubStr(%datetime,6,2);
%len = strLen(%y);
%last = getSubStr(%y,%len-2,2);
%y = (getSubStr(%y,0,%len-2)+(%last $= "99" && %comp $= "00" ? 1 : 0)) @ %comp;
$swol_currRealYear = %y;
}
return $swol_currRealYear;
}
--- End code ---
Navigation
Message Index
Next page

Go to full version