/    Sign up×
Community /Pin to ProfileBookmark

Display month (for the real wizzkid)

Hi All,

I want to display the what month it is, this is not so difficult.

<script languae=”Javascript”>
Now = new Date();
document.write(Now.getMonth());
</script>

BUT, now I want to display the month of 2 months ago.
So now it’s january it should display november.

And to make it even more difficult, after the 15th it should show
1 month back instead of 2 month.

So if the date is january 14th it should display : november
If the date is january 15th is should display : december.

How would I do this??

Thanks for any help!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Warren86Jan 24.2005 — <HTML>

<Head>

<Script Language=JavaScript>

var monthNames = "January,February,March,April,May,June,July,August,September,October,November,December"

monthNames = monthNames.split(",");

function calcJulian(isDate){

gregDate = new Date(isDate);
year = gregDate.getFullYear();
month = gregDate.getMonth()+1;
day = gregDate.getDate();
A = Math.floor((7*(year+Math.floor((month+9)/12)))/4);
B = day+Math.floor((275*month)/9)
isJulian = (367*year)-A+B+1721014;
return isJulian
}

function calcGregorian(isDate) {

X = parseInt(isDate);
Y = Math.floor((X-1867216.25)/36524.25);
A = X+1+Y-Math.floor(Y/4);
B = A+1524;
C = Math.floor((B-122.1)/365.25);
D = Math.floor(365.25*C);
E = Math.floor((B-D)/30.6001);
month = (E<13.5) ? (E-1) : (E-13);
day = Math.floor(B-D-Math.floor(30.6001*E));
isGregorian = month+"/"+day;
return isGregorian;
}

function init(){

isToday = new Date();
refDate = calcJulian(isToday);
straddleDate = calcGregorian(refDate);
straddleDate = straddleDate.split("/");
if (straddleDate[1] >= 15){disp = refDate-31}
if (straddleDate[1] < 15){disp = refDate-45}
dMonth = calcGregorian(disp);
dMonth = dMonth.split("/");
nMonth = dMonth[0];
document.getElementById('baseMonth').innerHTML = monthNames[nMonth-1];
}

window.onload=init;


</Script>

</Head>

<Body>

<Div id='baseMonth' style='font-size:14pt;color:blue'></Div>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@CharlesJan 24.2005 — [font=monospace]<script type="text/javascript">

<!--

Date.prototype.getPastMonth = function () {var d = new Date (this.getTime()); d.setMonth (d.getMonth() - (d.getDate() > 15 ? 1 : 2)); return d.getMonth()}

Date.MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

alert (Date.MONTHS [new Date().getPastMonth()])

// -->

</script>[/font]
Copy linkTweet thisAlerts:
@JuuitchanJan 25.2005 — Warren, we've seen those date functions of yours a zillion times and don't care to see them again. Besides, they don't even work right for this: try March 1 as the date.

But then again, if sfilipowicz cared about accuracy, would he be using JavaScript?
Copy linkTweet thisAlerts:
@PittimannJan 25.2005 — Hi![i]Originally posted by Juuitchan [/i]

[B]Warren, we've seen those date functions of yours a zillion times and don't care to see them again.[/B][/QUOTE]
What a pity! I got so used to the 'isJulian' and 'calcJulian' that I was close to apply for citizenship at the Vatican (that would seem closer to me to a Roman citizenship than the Italien one).

I will be, what I am, a Gregorian German ?

if(!isJulian('Pit'))return 'Gregorian German Pit';

else return 'erm';

Cheers - (depends on the return value)
×

Success!

Help @sfilipowicz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...