#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Date and Time

Posts: 4Member
I am writing a web page for a local television station, and I was wondering if anyone would be willing to help me by telling how to put the date and time(automatically updating)on the site. I appreciate all your help. Thanks

· ·

• Posts: 3Member
: I am writing a web page for a local television station, and I was wondering if anyone would be willing to help me by telling how to put the date and time(automatically updating)on the site. I appreciate all your help. Thanks
:
:
Sample in vbscript

Option Explicit

Function GetDate()
Dim MyWeekDay,MyDay,MyMonth,MyYear

MyWeekDay = WeekdayName(WeekDay(now),False)
MyDay = Day(now)
MyMonth = MonthName(Month(now),False)
MyYear = Year(now)

Select case(MyDay)
case 1,21,31 MyDay = MyDay & "st "
case 2,22 MyDay = MyDay & "nd "
case 3,23 MyDay = MyDay & "rd "
case else MyDay = MyDay & "th "
End select
GetDate = MyWeekDay & ", " & MyDay & MyMonth & space(1) & MyYear
End Function

Sub GetGreeting()
Dim MyHour,MyMin,MyAMPM,DateString,Greeting

MyHour = Hour(now)
MyMin = Minute(now)
DateString = GetDate()

if MyHour < 12 then
MyAMPM = "AM"
Greeting = "Good Morning"
if MyHour = 0 then MyHour = 12
else
MyAMPM = "PM"
if MyHour < 18 then
Greeting = "Good Afternoon"
else Greeting = "Good Evening"
end if
if MyHour <> 12 then MyHour = MyHour-12
end if

if MyMin < 10 then MyMin="0" & MyMin
MyGreeting.innerText = Greeting & ", Today is " & DateString & ", " _
& MyHour & ":" & MyMin & Space(1) & MyAMPM
End Sub

Sub InitGreeting()
window.setInterval "GetGreeting",1000
End Sub

Sample output:
Good Morning, Today is Tuesday, 18th March 2003, 9:23 AM
· ·
• Posts: 4Member
Thank you Turburki!
God Bless!
· ·
• Posts: 3Member
sample in javascript:

function GetDate(){
var MyDate,MyWeekDay,MyDay,MyDayName,MyMonthName;
MyDayName = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
MyMonthName = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
MyDate = new Date();
MyWeekDay = MyDate.getDay();
MyDay = MyDate.getDate();
MyMonth = MyDate.getMonth()
MyDayString = new String();

switch(MyDay){
case 1,21,31:
MyDayString = MyDay + "st ";
break;
case 2,22:
MyDayString = MyDay + "nd ";
break;
case 3,23:
MyDayString = MyDay + "rd ";
break;
default:
MyDayString = MyDay + "th ";
}
return MyDayName[MyWeekDay] + ", " + MyDayString + MyMonthName[MyMonth] + " " + MyDate.getFullYear();
}

function GetGreeting(){
var MyTime,MyHour,MyMin,MyAMPM,DateString,Greeting;
MyTime = new Date();
Greeting = new String();
MyAMPM = new String();
MyHour = MyTime.getHours();
MyMin = MyTime.getMinutes();

if (MyHour < 12){
MyAMPM = "AM";
Greeting = "Good Morning";
if (MyHour == 0){MyHour = 12;}
}
else { MyAMPM = "PM";
if (MyHour < 18){ Greeting = "Good Afternoon";}
else {Greeting = "Good Evening";}
if (MyHour != 12){MyHour = MyHour-12;}
}

if (MyMin < 10){ MyMin="0" + MyMin; }
MyGreeting.innerText = Greeting + ", Today is " + GetDate() + ", " + MyHour + ":" + MyMin + " " + MyAMPM;
}

function InitGreeting(){
window.setInterval('GetGreeting()',1000);
}

· ·