Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert human readable duration to Time Format SQL SERVER 2014

I have this data.

"2mn 56s", "30s 83ms", "2h 10mn"

How to convert these into time format:

hh:mn:ss - "00:02:56", "00:00:30", "02:10:00"
like image 989
Vince Avatar asked Feb 19 '26 18:02

Vince


1 Answers

In JavaScript, you can use String#replace method.

var str = '"2mn 56s", "30s 83ms", "2h 10mn"';

console.log(
  str.replace(/"(?:(\d)+h\s*)?(?:(\d+)mn\s*)?(?:(\d+)s\s*)?[^"]*"?/g, function(_, m1, m2, m3) {
    return [m1, m2, m3].map(v => ('00' +( v || '')).slice(-2)).join(':')
  })
)

Regex explanation here.

like image 66
Pranav C Balan Avatar answered Feb 21 '26 08:02

Pranav C Balan