how to add hours , minutes amd secs in same function in sybase..
SELECT dateadd(hh,3,getdate()
in this i need to add 3.5 [3hrs,30mins]. How to do that? can any one help me.
Can you add 210 minutes instead?
More specifically, convert to the smallest unit, and add that. You can't add fractions of units.
For some people, a more legible way would be:
SELECT dateadd(mi,30,dateadd(hh,3,getdate()))
Related
In our database time is stored in seconds. I need to pull the time out and convert into hours with a max of 2 decimal places.
I have the following
sum (CAST(vt.TIMEINSECONDS AS decimal(10,2))/3600) as AMOUNT_TAKEN
for most part it works, but sometimes it shows 39.9999998 instead of 40 hrs and in the reports i'm running due to the time being like that its causing issues. How can i get it to show 40
CAST the result after division
CAST(SUM(vt.TIMEINSECONDS)/3600.0 AS decimal(10,2)) as AMOUNT_TAKEN
I found the right way to the round the value for my issue.
sum (CAST(ROUND(vt.TIMEINSECONDS/60.0/60.0,2)AS decimal (6,2)))
Thank you to all that helped.
I'm creating a data table using DataTables.net where a column contains the cumulative running hours of an event. I'm simply adding to the hours each time, so I have for example:
40:34:30
which is 40 hours, 34 minutes, 30 seconds.
My problem is I want to order this column by hours, and I haven't been able to find anything that supports this from Moment.js. Ideally I imagine it would be something like "HHH:mm:ss", or something like that. As it stands, the column recognises the fields as strings, so 0:12:34 is appearing above anything else in descending order despite only being 12 minutes long.
You can sort HH:mm:ss by re-formating it to seconds before sorting.
moment.duration('40:34:30').asSeconds;
gives you 146070. Then simply use seconds in your sorting script.
here is the solution: jsFiddle
And if you really need just the hour part; use Math.floor: jsFiddle
I need to add decorators that will represent from 6 days ago till now.
how should I do it?
lets say the date is realative 604800000 millis from now and it's absolute is 1427061600000
#-604800000
#1427061600000
#now in millis - 1427061600000
#1427061600000 - now in millis
Is there a difference by using relative or absolute times?
Thanks
#-518400000--1
Will give you data for the last 6 days (or last 144 hours).
I think all you need is to read this.
Basically, you have the choice of #time, which is time since Epoch (your #1427061600000). You can also express it as a negative number, which the system will interpret as NOW - time (your #-604800000). These both work, but they don't give the result you want. Instead of returning all that was added in that time range, it will return a snapshot of your table from 6 days ago....
Although you COULD use that snapshot, eliminate all duplicates between that snapshot and your current table, and then take THOSE results as what was added during your 6 days, you're better off with :
Using time ranges directly, which you cover with your 3rd and 4th lines. I don't know if the order makes a difference, but I've always used #time1-time2 with time1<time2 (in your case, #1427061600000 - now in millis).
I have a time stored as a decimal(9,2) column in an sql-server 2005 database.
The time is represented like
Time timeInDecimal
1H 20Min 1.33
1H 30Min 1.50
and so on
I´m looking for an easy way to check whether the number of minutes except whole hours is not evenly divided by 5.
The value I'm hoping to find is where the time is 1H:23Min but not 1H:25MIN.
I just wan´t to compare the minute part of the time.
The way I do now is:
RIGHT(CONVERT(varchar(5),DATEADD(minute,ROUND(timeInDecimal * 60,0),0),108),1) not in ('0','5')
But it does hardly seems to be the ideal way to deal with this.
Feels like I can use the modulo operator for this, but how?
Or is there an even better way?
Hope for a quick answer.
Kind Regards
Andreas
Using the modulus operator, twice:
ROUND((timeInDecimal % 1) * 60, 0) % 5 <> 0
That will:
Get the fractional part and convert it to minutes.
Round it to the nearest minute (.33 hours -> 20 minutes, not 19.80).
Check whether that's divisible by 5.
My question is How can i calculate time duration between sunrise and sunset?
Then how can i divide this duration(sunrise to sunset) into 8 equal parts(Hr: Min)?
All i need is starting and ending time of every part. And i want to write this code in VB.NET
because in VB.NET i can easily design the GUI.
Thanks
A quick search for "sunrise VB.NET" came up with a few results, such as this one.
You can use TimeSpan. Add the sunrise and sunset to it, and then use timespan.Seconds, timespan.Hours etc
To devide it into 8 equal parts, just use timespan.Seconds / 8 and then calculate that into hours, minutes and seconds
If you don't already have the sunrise and sunset time, you can use this project to calculate it: http://www.codeproject.com/KB/cs/SunTime.aspx