Writing modified time with date to tags

I have a date selection window that has two calendars on it that is used to select a time period for a KPI history report. ‘[color=#0000BF]HistoryStartDate[/color]’ & ‘[color=#0000BF]HistoryEndDate[/color]’ are the names of the calendars. I take the date from each and populate global tags and client tags with the dates selected in the calendar. Our production days start at 0600 each morning. What I’m trying to do is allow the users to select the date and then add the 06:00:00 as the time to each date when it is inserted into the tag value. I’m fairly new at scripting and have looked a lot of this up online however, I’m still having an issue with making it work. It will insert the date with 00:00:00 as the time to each tag I have in the script but I can’t get it to change the time. I know I could do this with dateArithmetic functions but I have several other places where I need to change the time using the calendar so I’m trying to learn it now. Any help with explanations for where I’ve gone wrong would be greatly appreciated. Thanks in advance.

Here’s my script I’m using:

#This script will set the Start & End dates for the local client 
#	tags "[Client]ClientStartDateSelect" & "[Client]ClientEndDateSelect"

#Imports the utility libraries into the java application
from java.util import *

# Gets the date selected from 'HistoryStartDate'
StartDate = event.source.parent.getComponent('HistoryStartDate').date

# Forces the time returned to be 0600 hrs.
cal = Calendar.getInstance()
cal.set(Calendar.HOUR_OF_DAY, 6)
cal.set(Calendar.MINUTE, 0)
cal.set(Calendar.SECOND, 0)

#Gets the date selected from 'HistoryEndDate'
EndDate = event.source.parent.getComponent('HistoryEndDate').date

# Forces the time returned to be 0600 hrs.
cal = Calendar.getInstance()
cal.set(Calendar.HOUR_OF_DAY, 6)
cal.set(Calendar.MINUTE, 0)
cal.set(Calendar.SECOND, 0)




# Sets the following tags to the selected date at 0600 hrs.
system.tag.writeToTag('Melamine/GlobalTags/HistoryStartDateSelected', StartDate)
system.tag.writeToTag('[Client]ClientStartDateSelect', StartDate)
system.tag.writeToTag('Melamine/GlobalTags/HistoryEndDateSelected', EndDate)
system.tag.writeToTag('[Client]ClientEndDateSelect', EndDate)

#Closes the HistoryDateSelect Window
system.nav.closeParentWindow(event)

Take a look at my effort here:
http://www.inductiveautomation.com/forum/viewtopic.php?f=70&t=10428&p=37012&hilit=calendar#p37012

It may be long winded (???) but it does work.
After the date/time has been altered I use getTime() and this is what is written to the tag.

The code below worked for me for just the start time.

[code]#This script will set the Start & End dates for the local client

tags “[Client]ClientStartDateSelect” & “[Client]ClientEndDateSelect”

#Imports the utility libraries into the java application
from java.util import *

Gets the date selected from ‘HistoryStartDate’

start = event.source.parent.getComponent(‘HistoryStartDate’).date

startYear = system.db.dateFormat(start, “yyyy”)
startMonth = system.db.dateFormat(start, “MM” )
startDay = system.db.dateFormat(start, “dd” )

calStart = Calendar.getInstance()
calStart.set(Calendar.YEAR, int(startYear))
calStart.set(Calendar.MONTH, int(startMonth)-1)
calStart.set(Calendar.DAY_OF_MONTH, int(startDay))
calStart.set(Calendar.HOUR_OF_DAY, 6)
calStart.set(Calendar.MINUTE, 0)
calStart.set(Calendar.SECOND, 0)
startTime=calStart.getTime()

Forces the time returned to be 0600 hrs.

cal = Calendar.getInstance()
cal.set(Calendar.HOUR_OF_DAY, 6)
cal.set(Calendar.MINUTE, 0)
cal.set(Calendar.SECOND, 0)
s=cal.getTime()
#Gets the date selected from ‘HistoryEndDate’
#EndDate = event.source.parent.getComponent(‘HistoryEndDate’).date

Forces the time returned to be 0600 hrs.

#cal = Calendar.getInstance()
#cal.set(Calendar.HOUR_OF_DAY, 6)
#cal.set(Calendar.MINUTE, 0)
#cal.set(Calendar.SECOND, 0)

Sets the following tags to the selected date at 0600 hrs.

system.tag.writeToTag(‘HistoryStartDate’, startTime)
#system.tag.writeToTag(’[Client]ClientStartDateSelect’, StartDate)
#system.tag.writeToTag(‘HistoryEndtDate’, EndDate)
#system.tag.writeToTag(’[Client]ClientEndDateSelect’, EndDate)

#Closes the HistoryDateSelect Window
#system.nav.closeParentWindow(event)[/code]

Thank you Brett, that worked perfectly and I was able to modify it to work with the end time too. I can see I missed setting up quite a few variables needed to make it work. I appreciate your help on this and may try to use the work in your link to keep my users from selecting a start date beyond today or the selected end date.

Thanks

David