I am new to program in VBA i am stuck with a small conversion , I have an input data as "double", I have another 2 value as in time format . I want to add this double in time format and out put as time
Totalhours = 99 (double)
Starttime = 00:30:00 (hh:mm:ss)
Endtime = 00:30:00 (hh:mm:ss)
Result = 100 hours
I want to add Totalhours+Starttime +Endtime in a time format . I tried all possible way i didnt get the answer.
Code:
Totalinthrs = Int(Nuday * Worksheets("qwer").Range("C2").Value)
Totalhours = Int(Totalinthrs + Starttime)
Totalhours = Totalinthrs * 24
Worksheets("qwer").Range("C5").Value = TotHours
Totalhours = CDate(Totalhours)
Totalhours = TimeValue(Totalhours)
Totalhours = TotHours + Starttime + Endtime
You're on the right path but over-complicating...
Result = TotalHours + ((StartTime + EndTime) * 24)
gives a Result of 100.
Related
I am creating a software which would find out the production complete date based on start date.
This will be working like it would find out the total hours required to complete the production and then add it to start date.
Now I want to add hours based on how the Production shift is working. These checkboxes tell that weather the shift is working or not. If checkbox is checked it means shift is working, otherwise not.
Based on shift working, it would add the hours to date, For example
Based on Calculation the time required is 900 hrs, now if Monday and Tuesday only one shift is working then while calculating end date it would consider only 12 hours from this 900 hrs for Monday and Tuesday.
Screenshot of WinForm
production24 = ((rpm * 24 * 60) / (pick * 39.37)) * (eff / 100)
production12 = ((rpm * addvalue * 60) / (pick * 39.37)) * (eff / 100)
production1 = ((rpm * 1 * 60) / (pick * 39.37)) * (eff / 100)
production24 = Math.Round(production24, 2, MidpointRounding.AwayFromZero)
production12 = Math.Round(production12, 2, MidpointRounding.AwayFromZero)
production1 = Math.Round(production1, 2, MidpointRounding.AwayFromZero)
pro_24.Text = Convert.ToString(production24)
Pro_12.Text = Convert.ToString(production12)
Pro_1.Text = Convert.ToString(production1)
If fl <> 0 And production1 <> 0 Then
timereqinhr = fl / production1
Else
timereqinhr = 0
End If
getdate = DatePicker.Value + Time_Picker.Value.TimeOfDay
falldate = getdate.AddHours(timereqinhr + offshift)
fallingtime.Text = falldate.ToString("dd/MM/yyyy | hh:mm tt")
Label9.Text = "Time required for " + fabric_Length.Text + " Meters"
Dim productiontime, productionhr, productionmin As String
productiontime = Math.Floor(timereqinhr / 24)
productionhr = Math.Floor(((timereqinhr / 24) - productiontime) * 24)
productionmin = Math.Floor(((((timereqinhr / 24) - productiontime) * 24) * 60) - (productionhr * 60))
Label8.Text = (productiontime + " Days, " + productionhr + " Hours " + productionmin + " Min ")
How can I get total hours in Odoo 11?
start_time = fields.Datetime("Start Time")
end_time = fields.Datetime("End Time")
total_hours = fields.Integer("Total Hours")
Thanks.
I achieved this using
#api.depends('start_time','end_time')
def get_hours(self):
seconds = (self.end_time - self.start_time).total_seconds()
self.total_hours = seconds // 3600
start_time = fields.Datetime("Start Time")
end_time = fields.Datetime("End Time")
total_hours = fields.Integer("Total Hours",compute="get_hours",store=True)
and if want minutes also you can try this:
#api.depends('start_time','end_time')
def get_hours(self):
seconds = (self.end_time - self.start_time).total_seconds()
hours = seconds // 3600
minutes = (seconds % 3600) // 60
self.total_hours = '{} hours, {} minutes'.format(hours, minutes)
start_time = fields.Datetime("Start Time")
end_time = fields.Datetime("End Time")
total_hours = fields.Char("Total Hours",compute="get_hours",store=True)
I have to query reports based on the time given by me.
There are 4 slots of time: 0, 15, 30, 45.
Foe example, if the current time is 13:44, I will use time as 13:15 to 13:30 to query my reports; and if the current time is 13:04, I will use time as 12:30 to 13:45 to query my reports.
I have written the following code, but it uses lots of If and Else. Please help me with some better code.
Sub Test()
hh = Format(Time, "hh")
mm = Format(Time, "mm")
If (0 < mm < 15) Then mm = mm - 30
If (15 < mm < 30) Then mm = mm - 30
If (30 < mm < 45) Then mm = mm - 30
If (45 < mm < 60) Then mm = mm - 30
If (mm < 0) Then
mm = -mm
hr = hr - 1
End If
st = hh & "&" & mm
End Sub
You can use a little maths to round down to specific interval or bring the worksheet FLOOR function into play.
Option Explicit
Sub Test()
Dim tm As Double, st As String
tm = Application.Floor(Time, TimeSerial(0, 15, 0))
st = Format(tm, "hh\&mm")
Debug.Print st
End Sub
I can't figure out how to convert 12:00:00 AM to number/decimal. I tried to convert the Time Format to "Short Time" or "h.mm" but it didn't work and it still returns 0.
Dim dbConvertTime as Double
Dim dtTime as Date
dtTime = Format("12:00:00 AM","Short Time")
dbConvertTime = (dtTime * 24)
*Output
dbConvertTime = 0
I wanted convert the Time(12:00:00) to 24:00:00 because this data(12:00:00) returns 0 when multiplied by 24. The output should be = 576.00
Will return the hour of a timestamp
Hour(Now())
This will return a 24 hour format timestamp. If you want a 12 hour format you could do the following:
dtTime = IIf(Hour(tme) > 12 Or Hour(tme) = 0, Abs(Hour(tme) - 12), Hour(tme))
I've used abs here to return 12 for when time is 12 AM
Can someone please help me to make this work?
I want to calculate the time between two dates in VB.NET like this:
startdate: 2011/12/30
enddate: 2011/12/31
Calculate: ? hour ? minute ? seconds
You Can try this
DateTime startTime = DateTime.Now;
DateTime endTime = DateTime.Now.AddSeconds( 75 );
TimeSpan span = endTime.Subtract ( startTime );
Console.WriteLine( "Time Difference (seconds): " + span.Seconds );
Console.WriteLine( "Time Difference (minutes): " + span.Minutes );
Console.WriteLine( "Time Difference (hours): " + span.Hours );
Console.WriteLine( "Time Difference (days): " + span.Days );
Output Like,
Time Difference (seconds): 15
Time Difference (minutes): 1
Time Difference (hours): 0
Time Difference (days): 0
And the VB.Net equivalent to the above:
Dim startTime As DateTime = DateTime.Now
Dim endTime As DateTime = DateTime.Now.AddSeconds(75)
Dim span As TimeSpan = endTime.Subtract(startTime)
Console.WriteLine("Time Difference (seconds): " + span.Seconds)
Console.WriteLine("Time Difference (minutes): " + span.Minutes)
Console.WriteLine("Time Difference (hours): " + span.Hours)
Console.WriteLine("Time Difference (days): " + span.Days)
When you subtract 2 DateTimes, you get a TimeSpan struct that has all of those properties for you.
Based on the question, calculating the time between two dates, it is better to use DateDiff. On below example, we can also replace the Hour with Minute, Second, Month, etc.:
Dim timeDif As Long = DateDiff(DateInterval.Hour, startDate, endDate)
Using TimeSpan returns the time difference excluded the daily cycle, see below code:
Dim startDate As Date = Date.Now
Dim endDate As Date = startDate.AddDays(3) 'add 3 days to startDate
Dim timeSpan As TimeSpan = endDate.Subtract(startDate)
Dim difDays As Integer = timeSpan.Days 'get 3 days
Dim difHr As Integer = timeSpan.Hours 'get 0 hours although 3 days difference
Dim difMin As Integer = timeSpan.Minutes 'get 0 minutes although 3 days difference