Adding Current Date to Website

  • parrothead517
  • Newbie
  • Newbie
  • parrothead517
  • Posts: 11

Post 3+ Months Ago

I want to add today's date to a website and have it automatically update. I have tried a couple scripts I found online, but they don't seem to be working (http://www.doggiestepsdogtraining.com - the date "should" be under the photo at the top left). I'm wondering if it's not working because it's inside an editable region in a Dreamweaver template? Can anyone help?

Thank you!
Lindsay
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Fairly simple to do with Javascript. Try this tutorial.
  • parrothead517
  • Newbie
  • Newbie
  • parrothead517
  • Posts: 11

Post 3+ Months Ago

Thank you! This worked great! How hard is it to edit the script I used (below) to have the month spelled out??
Code: [ Select ]
<script type="text/javascript">
<!--
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)
//-->
</script>
  1. <script type="text/javascript">
  2. <!--
  3. var currentTime = new Date()
  4. var month = currentTime.getMonth() + 1
  5. var day = currentTime.getDate()
  6. var year = currentTime.getFullYear()
  7. document.write(month + "/" + day + "/" + year)
  8. //-->
  9. </script>
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Not difficult at all. Just create an array containing the month names and use the month value as the index (you'll want to get rid of the "+ 1" on the month value).

Code: [ Select ]
<script type="text/javascript">
<!--
var months = new Array(
"January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December");
var currentTime = new Date();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.write(months[month] + " " + day + ", " + year);
//-->
</script>
  1. <script type="text/javascript">
  2. <!--
  3. var months = new Array(
  4. "January", "February", "March", "April",
  5. "May", "June", "July", "August", "September",
  6. "October", "November", "December");
  7. var currentTime = new Date();
  8. var month = currentTime.getMonth();
  9. var day = currentTime.getDate();
  10. var year = currentTime.getFullYear();
  11. document.write(months[month] + " " + day + ", " + year);
  12. //-->
  13. </script>
  • Carciel
  • Born
  • Born
  • Carciel
  • Posts: 1

Post 3+ Months Ago

spork, thank you very much. All is working as foreseen. I modded the code a little to show the Russian names for the days of week following your logic and it worked!
  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1244
  • Loc: Sydney

Post 3+ Months Ago

This is the wonders of JavaScript, it is really not that hard once you understand the basic's. it takes the time from the computer :P

if you need some reference check w3schools JS section, find some handy stuff there.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: ScottG and 108 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.