Need some help with this script. When I run this script it works well. However, at the end of the day it freezes at evening. The following day when I run the script it starts at evening, and it should start by saying morning. Am I missing something?

string timeOfDay;

dialog getTimeOfDay (out string TOD) {
			string time = formatDate(now(), "HHmm");
			if (time =~ '(?:[0-1]) (?:[0-1]) (?:[0-5]) (?:[0-9])'){
					TOD = "morning";
			}//Closes Morning String
			elif (time =~ '(?:1) (?:[2-6]) (?:[-5]) (?:[0-9])') {
					TOD = "afternoon";
			}//Closes Afternoon String
			else TOD = "evening";

call getTimeOfDay(out timeOfDay);

This should do it!
Good day to you...

<html>
<head>
<title><!-- Sample --></title>
<script type="text/javascript">
<!-- BEGIN HIDING
var today = new Date();
Date.prototype.greet = function()
{ hour = today.getHours();
  minute = today.getMinutes();
  second = today.getSeconds();
var greetings = '';  
if (( hour >= 7 ) && ( hour < 12 )) { greetings = 'GoodMoning! '; }
else if (( hour >= 12 ) && ( hour < 17 )) { greetings = 'GoodAfternoon! '; }   
else { greetings = 'GoodEvening! '; }
var apos = ( hour < 12 ) ? ' am' : ' pm';  
hour = ( hour >= 13 ) ? hour -12 : hour;
  hour = ( hour == 0 ) ? 12 : hour;

  minute = ( minute < 10 ? '0' : '' ) + minute;
  second = ( second < 10 ? '0' : '' ) + second;   
return greetings + '\nThe Time is now ' + hour + ':' + minute + ':' + second + apos;
}

window.onload = function() {
alert( today.greet() );
}
// DONE HIDING -->
</script>
</head>
<body>
<!-- ///////////////*\\\\\\\\\\\\\\ -->
</body>
</html>
commented: nice script... +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.