Javascript question #2

User 188640 Photo


Registered User
614 posts

It's been a long time since I've been in the forum but I have a Javascript question for the coders.

I have a website that has an entry that has how many years the business has been in business. I would like to automate that so I don't have to do it manually every year.

Does anyone know of a script that will do that or will I have to write one from scratch? I've tried searching the web for a script but I'm not sure what to ask for. I've found all kinds of date scripts but that won't work. (I think)

Any help finding what I'm looking for would be great so thanks for any replies.
A Rose is Just a Weed in a Corn Patch!
User 122279 Photo


Senior Advisor
11,274 posts

Can you use this one?
Company name <script type=
"text/javascript">
<!--
//Script created by Ronny Drappier, http://sipreal.com
//Visit http://javascriptkit.com for this script
today=new Date();
y0=today.getFullYear();
// end hiding --->
</script> &copy; Enter start year here -<script type=
"text/javascript">
<!--- Hide from old browsers
document.write(y0);
// end hiding --->
</script>
Ha en riktig god dag!
Inger, Norway
My new honey site, built with RFF: http://www.horgenhonning.net/
Component sharing for RFF, RBB, RSD and SD: http://www.horgenhonning.net/sharing/


User 188640 Photo


Registered User
614 posts

Hi Inger,
I will try that and see if it does what I'm trying to accomplish. It kind of looks like the script I have to update the copyright year so I'm not sure if it will work.

I'm trying to update the 'number of years in business' on a website.

I'll see if this works and thank you very much.
A Rose is Just a Weed in a Corn Patch!
User 188640 Photo


Registered User
614 posts

No, that's the same script I have for the footer. That just updates the copyright year. I'll keep hunting.
A Rose is Just a Weed in a Corn Patch!
User 122279 Photo


Senior Advisor
11,274 posts

Sorry about that. I must have misunderstood what you wanted
Ha en riktig god dag!
Inger, Norway
My new honey site, built with RFF: http://www.horgenhonning.net/
Component sharing for RFF, RBB, RSD and SD: http://www.horgenhonning.net/sharing/


User 379556 Photo


Registered User
659 posts

An extremely simple solution seems as in this RSD file.

All I did was to have a text element with the id of this-year, and create a custom attribute for the Grid as follows -
Name: onload
Value: document.getElementById("this-year").innerHTML = new Date().getFullYear()-1999;

The 1999 at the end of the Value is the year when the business started.

Frank
User 187934 Photo


Senior Advisor
18,050 posts

Do you need it right to the day?
if not
<script>
var now = new Date();
var todayAtMidn = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var businessStart = new Date("2/29/2009");
var yearsBusiness = todayAtMidn.getFullYear() - businessStart.getFullYear()
document.write("We've been in business for "+yearsBusiness+" years.");
</script>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

Here's my S-Drive site with
examples of what can be accomplished in VSD.
http://progrower.coffeecup.com/
Here's my CoffeeCup SCCP Shop with examples of what can be done.
http://progrower.coffeecup.com/shop/
This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personnel site used for testing and as an easy way to share photos.(RLM imported to RSD)
http://ericrohloff.com
http://ericrohloff.com/property/
User 122279 Photo


Senior Advisor
11,274 posts

Here is one I found, but it counts the days. You may be able to adapt it.

<script>

/*
Count up from any date script-
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countup(yr,m,d){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy
var paststring=montharray[m-1]+" "+d+", "+yr
var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1)
difference+=" days"
document.write("It\'s been "+difference+" since the launch of JavaScript Kit!")
}
//enter the count up date using the format year/month/day
countup(1997,12,05)
</script>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>
Ha en riktig god dag!
Inger, Norway
My new honey site, built with RFF: http://www.horgenhonning.net/
Component sharing for RFF, RBB, RSD and SD: http://www.horgenhonning.net/sharing/


User 187934 Photo


Senior Advisor
18,050 posts

This one will base it on days.
<script>
var now = new Date();
var businessStart = new Date("2/27/2010");;
var YearsinBus = Math.floor(((now-businessStart)/(1000*60*60*24))/365);
document.write("We've been in business for "+YearsinBus+" years.");
</script>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

Here's my S-Drive site with
examples of what can be accomplished in VSD.
http://progrower.coffeecup.com/
Here's my CoffeeCup SCCP Shop with examples of what can be done.
http://progrower.coffeecup.com/shop/
This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personnel site used for testing and as an easy way to share photos.(RLM imported to RSD)
http://ericrohloff.com
http://ericrohloff.com/property/
User 188640 Photo


Registered User
614 posts

Thank you everyone for the help.
I'll dig into all these this evening and see which one does the best.
A Rose is Just a Weed in a Corn Patch!

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.