[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1136
  • Last Modified:

Date Hours Minutes and AM/PM in javascript function

In my javascript function I am getting date value as show below

var sDate=Cal.FormatDate(PValue);
var sHours=winMain.Cal.getShowHour();
var sMinutes=winMain.Cal.Minutes;
var sAMPM=winMain.Cal.AMorPM;

when we consolidate all the above the final date will look like eg: 11/16/2006 03:15 PM

Now I want to add 30 Minutes to the minutes which should take all the following scenarios: like if I add 30 minutes to
11/16/2006 11:45 PM
it should show  11/17/2006 00:15 AM

and so on

Please help
0
rowmark
Asked:
rowmark
1 Solution
 
MessiadbunnyCommented:
<script type="text/javascript">

curdate = new Date()

dateVar = new Date(curdate.getFullYear(), curdate.getMonth(), curdate.getDate(),curdate.getHours(),curdate.getMinutes() + 30,curdate.getSeconds())
//This collects all the data from the current date, except adds 30 mins as shown above
// curdate.getMinutes() + 30 is the specific line that adds 30 mins.

if (dateVar.getHours() < 12 & dateVar.getHours() > 0)
{
//If time is less than noon, but before 1 AM
curhour = dateVar.getHours()
ampm = "A.M."
}
else if (dateVar.getHours() == 12)
{
//If it's exactly 12 PM (Noon ish)
curhour = 12
ampm = "P.M."
}
else if (dateVar.getHours() == 0)
{
//1 AM in the morning
curhour = 1
ampm = "A.M."
}
else
{
//If it's any other time, 1 PM - 12 PM
curhour = dateVar.getHours() - 12
ampm = "P.M."
}

mdhour = curhour
mdminute = dateVar.getMinutes()
mdyear = dateVar.getFullYear()
mdmonth = dateVar.getMonth()
mdday = dateVar.getDate()

//re-collect all the variables incase the day/month/year/ have changed with the addition of //30 mins.

document.write(mdmonth + "/" + mdday + "/" + mdyear + " " + mdhour + ":" + mdminute + " " + ampm)




</script>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now