/    Sign up×
Community /Pin to ProfileBookmark

Alternative Number Based on Year

I have tried a few scripts with poor results.

I am attempting to create an output of a numerial that is found equal to the current year and increases by one every year. Essentially giving the identity of the year another identity.

For example…
If the get date was January 1, 2005
Rewrite would print Janaury 1, 487
2005 equals 487
2006 will equal 488
2007 will equal 489
et cetera…

I used a get date base to start from 1970 and progress up but it did not pan out. Any help is appreciated.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterOct 30.2005 — All you are doing is minusing the current date by 1518. What's so hard about that?
Copy linkTweet thisAlerts:
@CharlesOct 30.2005 — <script type="text/javascript">
Date.prototype.getFauxDate = function () {
var d = new Date (this.getTime())
d.setYear (d.getFullYear() - 1518)
return d
}

alert (new Date().getFauxDate().toDateString())
</script>
Copy linkTweet thisAlerts:
@RingsideauthorNov 03.2005 — Issue 1

Here is an interesting thing that I have no idea about. Once you reset the subtraction (ex 1518) to a number greater than 1900, the new year is incorrect.

Issue 2

This is probably also dumb but I tried dropping the first part of the date leaving only the year to be written however in this script you provided (which thank you very much by the way) the same manner of removing the other date parameters doesn't apply.

Thanks Charles.
Copy linkTweet thisAlerts:
@KorNov 03.2005 — you may also use a different approach
[code=php]
<script type="text/javascript">
var today = new Date();
var y = today.getFullYear()
var m = today.getMonth();
var d = today.getDate()
var newdate = new Date(y-1518,m,d)
alert(newdate.toDateString())
</script>
[/code]
Copy linkTweet thisAlerts:
@RingsideauthorNov 03.2005 — Same problem on the year subtraction. When you surpass 1900 on the subtraction, it goes back to 1900's
Copy linkTweet thisAlerts:
@KorNov 04.2005 — getFullYear() is rather an imperfect method. It was designed to bypass the Y2K possible bug but I guess that it will simply add 1900 to the year, if the clock returns an year with two digits. If so, probably it will be enough to point that:

[code=php]
<script type="text/javascript">
var substract = 1906;
var today = new Date();
var y = today.getFullYear()
var m = today.getMonth();
var d = today.getDate()
var newdate = new Date(y-substract,m,d)
var newyear = newdate.getFullYear();
newyear =(substract>(y-100))?newyear-1900:newyear;
alert(newyear)
</script>
[/code]


I reckon I don't know if the full date is real, I mean if the day of the week is correct, but you may verify that.
Copy linkTweet thisAlerts:
@RingsideauthorNov 04.2005 — Slight rework as well and it seems to have held. Thank you very much.
×

Success!

Help @Ringside 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...