Jump to content
UBot Underground

Javascript - Calculate Date From Daynumber


Recommended Posts

I got this off of stackoverflow, the date object is Javascript is very complicated,I dont know how the code works,but it seems to be accurate
today is the 267th day of the year as per 
http://www.epochconverter.com/epoch/daynumbers.php
 
if you want some sort of calculator for different time periods try this

define $dayNum(#day, #month, #year) {
    run javascript("function dayNo(y,m,d)\{
  return --m>=0 && m<12 && d>0 && d<29+(  
           4*(y=y&3||!(y%25)&&y&15?0:1)+15662003>>m*2&3  
         ) && m*31-(m>1?(1054267675>>m*3-6&7)-y:0)+d;
\}")
    set(#today, $eval("var todayIs = dayNo({#year},{#month},{#day})
todayIs"), "Local")
    return(#today)
}
set(#days, $dayNum(24, 09, 2015), "Global")

or just a function to return today without input

set(#today, $eval("function dayNo(y,m,d)\{
  return --m>=0 && m<12 && d>0 && d<29+(  
           4*(y=y&3||!(y%25)&&y&15?0:1)+15662003>>m*2&3  
         ) && m*31-(m>1?(1054267675>>m*3-6&7)-y:0)+d;
\}

function dayOfTheYear()\{

var myTime = new Date()

return dayNo(myTime.getYear(),myTime.getMonth()+1,myTime.getDate())
\}
var todayIs = dayOfTheYear()
todayIs

"), "Global")
Link to post
Share on other sites

Also keep the Leap year in mind.

Not sure whether that already has been integrated within that js code.

thanks

 

Yeah I didn't think of that but luckily the guy who wrote that code,did

 

set(#days$dayNum(31, 12, 2012), "Global")

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...