HIVE:how to calculate seconds difference of time format: yyyyMMdd HH:mm:ss




How to calculate seconds difference of time format:`yyyyMMdd HH:mm:ss`?
For example,calculate seconds difference of `20190102 00:01:05` and `20190102 02:14:18`
Use [UNIX\_TIMESTAMP](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions) function to convert timestamps to seconds, then subtract:



```
select UNIX_TIMESTAMP('20190102 02:14:18','yyyyMMdd HH:mm:ss') -
       UNIX_TIMESTAMP('20190102 00:01:05','yyyyMMdd HH:mm:ss');

```

Returns:


`7993` seconds. 


Difference in `'HH:mm:ss'` format:



```
select from_unixtime(UNIX_TIMESTAMP('20190102 02:14:18','yyyyMMdd HH:mm:ss') -
       UNIX_TIMESTAMP('20190102 00:01:05','yyyyMMdd HH:mm:ss'), 'HH:mm:ss');

```

Returns:



```
02:13:13

```
Hi,  

  

check the following Code  

SQLCopy Code

```
-- Question 1 Answer
SELECT E.EmployeeID,E.Day, (E.TotalTime/60) 'TotalHours', (E.TotalTime%60) 'Minites'
FROM (SELECT EmployeeID,CONVERT(VARCHAR(10),FromTime,102) 'Day',SUM(DATEDIFF(mi,FromTime,ToTime)) 'TotalTime'
      FROM tblEmployeeTimeCard
      GROUP BY EmployeeID,CONVERT(VARCHAR(10),FromTime,102))E

-- Question 1&2 Answer
SELECT E.EmployeeID,E.Day, (E.TotalTime/60) 'TotalHours', (E.TotalTime%60) 'Minites',
CASE WHEN (E.TotalTime/60)>=6 THEN E.TotalTime - (30* ROUND((E.TotalTime/60*6),1))
     ELSE (E.TotalTime/60) END 'TotalWorkHours'
FROM (SELECT EmployeeID,CONVERT(VARCHAR(10),FromTime,102) 'Day',SUM(DATEDIFF(mi,FromTime,ToTime)) 'TotalTime'
      FROM tblEmployeeTimeCard
      GROUP BY EmployeeID,CONVERT(VARCHAR(10),FromTime,102))E
```
  

  

For ur Question 2, I am not getting. give some more details about that. if possible send some sample data. if access over lap like (From date is 2013 -04-05 11:55:00PM to 2013-04-05 19:10:00PM)  

then we can't able to fine the time difference. So check the code for Question No 1 and give the feedback.  

  

Regards,  

GVPrabu hint: here, we will proceed by finding out the relative speed between the two cars and then using the formula i.e., time taken$ = \dfrac{{{\text{distance travelled}}}}{{{\text{speed}}}}$ to determine after how many hours these cars will meet each other.complete step-by-step answer:given, distance between the two cars d=160 kmstarting time for both the cars when they left their respective initial positions a and b is 8:10 amspeed of the first car, x=50 km per hourspeed of the second car, y=30 km per hourin order to obtain the relative speed between these two cars which are moving towards each other (i.e., in opposite directions), the individual speeds of these cars will be added.so, the relative speed between the two given cars, r= x+y=50+30=80 km per houras we know that, time taken$ = \dfrac{{{\text{distance travelled}}}}{{{\text{speed}}}}$so, time when both the cars will meet=$\dfrac{{{\text{initial distance between both the cars}}}}{{{\text{relative speed between the cars}}}} = \dfrac{{\text{d}}}{{\text{r}}} = \dfrac{{160}}{{80}} = 2$ hours.after 8:10 am, both the cars which are initially at different places a and b will meet each other in the next 2 hours.therefore, time when they will meet each = 8:10 am + 2 hours = 10:10 amhence, option a is correct.note: in this particular problem, since the given two cars are moving in opposite directions (or moving towards each other) that’s why the individual speed of the cars are added in order to determine the relative speed between them but if they were moving in the same direction then the relative speed between these cars would have been obtained by subtracting the individual speed of these cars. the formulas for converting between degree celsius and degree fahrenheit are: °f = (°c * 9/5) + 32 °c = (°f - 32) * 5/9 to find the temperature when both are equal, we use an old algebra trick and just set of = oc and solve one of the equations. °c = (°c * 9/5) + 32 °c - (°c * 9/5) = 32 - 4/5 * °c = 32 °c = - 32 * 5/4 °c = - 40 °f = (°f * 9/5) + 32 °f - (°f * 9/5) = 32 - 4/5 * °f = 32 °f = - 32 * 5/4 °f = - 40 so the temperature when both the celsius and fahrenheit scales are the same is - 40 degrees. class intervals
frequency
(fi)
xi
di = xi - a
fi di


0 - 20
17
10
-40
-680


20 - 40
28
30
-20
-560


40 - 60
32
50 = a
0
0


60 - 80
p
70
20
20p


80 - 100
19
90
40
760


total
Î£
fi = 96 + p


Î£ fi di = 20p -
480


![](https://s3mn%20mnimgs%20com/img/shared/discuss_editlive/5130830/2013_07_08_13_01_36/mathmlequation8813644107607516415%20png) Looks like YYMMDD to me. I would try to verify this in the documentation or whatever information source you have on the old database. You could also look for inappropriate numbers like MM not between 1 and 12 and DD not between 1 and 31. If you find any inappropriate numbers than this is the wrong approach. This does not look like a date based on an offset number of days after a start date because the start date would have to be about 2600 years ago. how about this?

fn write\_some\_content(&mut self, hour: u32) -> result<(), std::io::error> {

if self.current\_hour != hour {

if let some(writer) = self.current\_file.as\_mut() {

writer.flush()?;

}

self.current\_file = none;

self.current\_hour = hour;

}

… the relationship of wavelength and frequency will appear as:using the wavelength range given, 280-320 nm, frequency range will be calculated using the equation above and by converting the values to the proper units [readmore]each wavelength must be in meters:we need to calculate the frequency for both 280 and 320 nm:range of frequency will appear as 1.07x1015 to 9.38x1014 s-1 let the speed of train = x km /hlet the speed of car = y km/hcase 1 : 120 km by train and 480 by cartime taken to travel 120 km by train = 120x hrstime taken to travel 120 km by car = 480x hrsaccording to first condition :120x + 480y = 8⇒1x + 4y = 115     
1case 2 : 200 km by train and 400 by cartime taken to travel 200 km by train = 200x hrstime taken to travel 400 km by car = 400x hrsaccording to second condition :    200x + 400y = 82060 = 813 = 253         as, 20 min = 2060 hr = 13 hr⇒1x + 2y = 124     
2subtracting 2 from 1, we get      2y = 115 - 124⇒2y = 8-5120⇒y = 80now, from 1, we get    1x + 480 = 115⇒1x = 11 - 120 = 160⇒x = 60so, speed of train = 60 km/hspeed of car = 80 km/h [image] akanksha\_varshney:

(convert.tostring(date\_created\_hs.substring(0,10)).equals(convert.tostring(date\_created\_cchq.substring(0,10)))) or (date\_created\_hs <> “”)

hey,

try with the following one,

(convert.tostring(date\_created\_hs.substring(0,10).trim).equals(convert.tostring(date\_created… [readmore]typed answerh2 + i2 ⇌ 2hi      kc = 4.6i            0.5   0.5     0.5c          -x      -x       +2xe        0.5-x 0.5-x   0.5+2xkc=hi2hii2kc=0.5+2x20.5-x0.5-xkc=0.5+2x20.5-x24.6=0.5+2x0.5-xx=0.138hi=0.5+2x=0.776 m