Solved

Date Hours Minutes and AM/PM in javascript function

Posted on 2006-11-16
1
1,126 Views
Last Modified: 2012-06-27
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
Comment
Question by:rowmark
1 Comment
 
LVL 2

Accepted Solution

by:
Messiadbunny earned 500 total points
ID: 17962877
<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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question