/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Date function help

I am trying to come up with a function that will display the full 4 digit year inside of a footer div. I know how to do it with document.write getFullYear() call but i need to apply it in a function.

Any ideas?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@DanInMANov 08.2011 — use innerHTML instead of document.write
Copy linkTweet thisAlerts:
@alannauthorNov 08.2011 — I have since come across this code:

[code=html]<p>&copy; <script language="JavaScript" type="text/javascript">
now = new Date
theYear=now.getYear()
if (theYear < 1900)
theYear=theYear+1900
document.write(theYear)
</script> Somecompany, Inc. All Rights reserved.</p>[/code]


I need to create this as a function that will be placed in an external js file. It will need to be called on several pages within the company website.

My line of thinking is this:

[code=html]<script language="JavaScript" type="text/javascript">
function copyDate(){
now = new Date
theYear=now.getYear()
if (theYear < 1900)
theYear=theYear+1900
document.write(theYear)
}
</script>


<p>&copy; document.inner.HTML(copyDate) Somecompany, Inc. All Rights reserved.</p>[/code]
Copy linkTweet thisAlerts:
@DanInMANov 08.2011 — [CODE]


<p>&copy; <span id="copydate"></span> Somecompany, Inc. All Rights reserved.</p>
<script type="text/javascript">
now = new Date
theYear=now.getYear()
if (theYear < 1900)
theYear=theYear+1900
document.getElementById('copydate').innerHTML= theYear
</script>[/CODE]
Copy linkTweet thisAlerts:
@alannauthorNov 08.2011 — Its not working.
Copy linkTweet thisAlerts:
@DanInMANov 08.2011 — woops sorry, I edited the post.
Copy linkTweet thisAlerts:
@alannauthorNov 08.2011 — I am lost now. Should I just use the last line that you changed?
×

Success!

Help @alann 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.18,
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,
)...