How to insert automatic date in a website
I am making a small website for my project work. I have done almost everything like the body, images, etc. Now I want codes to insert a automatic date in the website. Like the visitor views the web page on the internet he must be able to see the current date. Send me some codes to add a date in the web page.
Re: How to insert automatic date in a website
The below is small script of java codes to add a date in the web page. You can edit it as per your need. By adding this into your website you will get an date listed in your website and it will change everyday.
HTML Code:
<script language="JavaScript" type="text/JavaScript">
var updMonths = ["1","2","3","4","5","6","7","8","9","10","11","12"];
var updDate = new Date(document.lastModified);
var updTxt = updDate.getDate() + '/'+updMonths[updDate.getMonth()]+'/'+updDate.getFullYear();
document.write(updTxt);
</script><noscript>Script for automatisk dato</noscript>
Re: How to insert automatic date in a website
Below is my basic workout for your date issue. Copy the below codes and paste it in the place where you want to see the date. After that save your page and reload it. Check out weather it need some editing or not.
PHP Code:
<script>
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000) year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10) daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write(""+montharray[month]+" "+daym+", "+year+"")
</script>
Re: How to insert automatic date in a website
As you are just using a website for a project work here it is a simple one line code to insert a date in the web page. copy paste the code in the website html script. And just insert this and very important in your properties make sure .php is selected instead of html.
PHP Code:
<?
echo date('l, F j, Y');
?>
Re: How to insert automatic date in a website
Im extremely new to all this (html, css and js) and was wondering If I wanted to put the date to be displayed somewhere on my website how can i display it in a txt box on my page, rather than only be displayed at the top of my page at current.
Im trying to add this code, (well not this exact code but something very similar) to my html/css webpage.
Thank you so much in advance,
-Max
Quote:
Originally Posted by
Katty
Below is my basic workout for your date issue. Copy the below codes and paste it in the place where you want to see the date. After that save your page and reload it. Check out weather it need some editing or not.
PHP Code:
<script>
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000) year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10) daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write(""+montharray[month]+" "+daym+", "+year+"")
</script>
Re: How to insert automatic date in a website
You can use the JavaScript date functions and the document.lastModified properties to get the date and print it out. If you want to put in the full word for "Mon" or "Jan", you just need to change the wording in the script.
Re: How to insert automatic date in a website
Hi,
I used the code Katty posted (which is really useful, thx) but now I'm trying to figure out how to stylize the text (bold, underline, italics etc)... could anyone help me out?
Re: How to insert automatic date in a website
Yes just paste before the script example <font size="6" face="Katy Berry" color="gray">
Re: How to insert automatic date in a website
Quote:
Originally Posted by
Katty
Below is my basic workout for your date issue. Copy the below codes and paste it in the place where you want to see the date. After that save your page and reload it. Check out weather it need some editing or not.
PHP Code:
<script>
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000) year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10) daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write(""+montharray[month]+" "+daym+", "+year+"")
</script>
Thank you very much :) :notworthy