# Converting milliseconds to minutes

Hi,
I have log file which contains the below information:
Data started: 02:39
Data ended: 04:25
Time taken: 60000

Data started: 04:39
Data ended: 02:25
Time taken: 70000

I want “Time Taken” value to convert into minutes.

-Kalyan

What is the value now? Seconds?

```New-TimeSpan -Seconds 70000
New-Timespan -Seconds (70000/1000)
[Math]::Round(70000/60)
[Math]::Round(70000/(1000*60))```

You can use New-Timespan or just a math equation.

Hi Jones,
Now, it is milliseconds.

-Kalyan

Hi Craig,
Thanks. But in the log file, every third line “Time taken” filed is there.

How do I convert every “Time Taken” field.

NOTE: The “Time taken” value keeps on changing.

-Kalyan

So you are trying to rewrite the log file with that line converted?

It’s actually “Don” or “Mr. Jones”

So if the start is…

```Data started: 02:39
Data ended: 04:25
Time taken: 60000

Data started: 04:39
Data ended: 02:25
Time taken: 70000```
```foreach (\$line in (Get-Content filename.txt)) {
if (\$line -like '*time*') {
\$pieces = \$line -split ' '
\$milliseconds = \$pieces[1]
\$seconds = \$milliseconds / 1000
}
}
```

and then you can do whatever you want with \$seconds.

Hi Craig,
Or we can output the result to a new file.
Same file will also good.

-Kalyan

Hi Don,
Tried the below:
foreach (\$line in (Get-Content VIS_PRD_Data_Aggregation_Log.txt)) {
if (\$line -like ‘Time taken for whole process’) {
\$pieces = \$line -split ’ ’
\$milliseconds = \$pieces[1]
\$seconds = \$milliseconds / 1000
}
}

Nothing is happening.

-Kalyan

Hi,
It says:
Cannot convert value “taken” to type “System.Int32”. Error: “Input string was not in a correct
format.”

• `````` \$seconds = \$milliseconds / 1000
``````
• `````` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``````
• CategoryInfo : InvalidArgument: ( , RuntimeException
• FullyQualifiedErrorId : InvalidCastFromStringToInteger

-Kalyan

Apologies.

```foreach (\$line in (Get-Content filename.txt)) {
if (\$line -like '*time*') {
\$pieces = \$line -split ' '
\$milliseconds = \$pieces[2]
\$seconds = \$milliseconds / 1000
# for example... "Time Taken: \$seconds" | Out-File whatever.txt -Append
} else {
# for example... \$line | Out-File whatever.txt -Append
}
}
```

Thanks. Let me try on this.

-Kalyan

Modified the script & made it working: Below is the script:
foreach (\$line in (Get-Content test.txt)) {
if (\$line -like ‘process’) {
\$pieces = \$line -split ’ ’
\$seconds = [math]::round( (\$pieces[6]) / 1024)
write-host \$seconds
}
}

Just have a question, by using the script I am able to convert milliseconds to minutes.

Can I replace these values in the log:
Data started: 02:39
Data ended: 04:25
Time taken: 60000

Data started: 04:39
Data ended: 02:25
Time taken: 70000

-Kalyan

Hi,
Finally modified the script a bit & able to convert to minutes and replace in the same file.

Thanks,
-Kalyan