Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 108441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:54:44+00:00 2026-05-11T01:54:44+00:00

I have a tab delimited file where each record has a timestamp field in

  • 0

I have a tab delimited file where each record has a timestamp field in 12-hour format:

mm/dd/yyyy hh:mm:ss [AM|PM].

I need to quickly convert these fields to 24-hour time:

mm/dd/yyyy HH:mm:ss.

What would be the best way to do this? I’m running on a Windows platform, but I have access to sed, awk, perl, python, and tcl in addition to the usual Windows tools.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:54:45+00:00Added an answer on May 11, 2026 at 1:54 am

    Using Perl and hand-crafted regexes instead of facilities like strptime:

    #!/bin/perl -w while (<>) {     # for date times that don't use leading zeroes, use this regex instead:     # (?:\d{1,2}/\d{1,2}/\d{4} )(\d{1,2})(?::\d\d:\d\d) (AM|PM)     while (m%(?:\d\d/\d\d/\d{4} )(\d\d)(?::\d\d:\d\d) (AM|PM)%)     {         my $hh = $1;         $hh -= 12 if ($2 eq 'AM' && $hh == 12);         $hh += 12 if ($2 eq 'PM' && $hh != 12);         $hh = sprintf '%02d', $hh;         # for date times that don't use leading zeroes, use this regex instead:         # (\d{1,2}/\d{1,2}/\d{4} )(\d{1,2})(:\d\d:\d\d) (?:AM|PM)         s%(\d\d/\d\d/\d{4} )(\d\d)(:\d\d:\d\d) (?:AM|PM)%$1$hh$3%;     }     print; } 

    That’s very fussy – but also converts possibly multiple timestamps per line.

    Note that the transformation for AM/PM to 24-hour is not trivial.

    • 12:01 AM –> 00:01
    • 12:01 PM –> 12:01
    • 01:30 AM –> 01:30
    • 01:30 PM –> 13:30

    Now tested:

    perl ampm-24hr.pl <<! 12/24/2005 12:01:00 AM 09/22/1999 12:00:00 PM 12/12/2005 01:15:00 PM 01/01/2009 01:56:45 AM 12/30/2009 10:00:00 PM 12/30/2009 10:00:00 AM !  12/24/2005 00:01:00 09/22/1999 12:00:00 12/12/2005 13:15:00 01/01/2009 01:56:45 12/30/2009 22:00:00 12/30/2009 10:00:00 

    Added:

    In What is a Simple Way to Convert Between an AM/PM Time and 24 hour Time in JavaScript, an alternative algorithm is provided for the conversion:

    $hh = ($1 % 12) + (($2 eq 'AM') ? 0 : 12); 

    Just one test…probably neater.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tab delimited text file that I need to upload to a
I have to parse a tab-delimited text file with Ruby to extract some data
I have a tab-delimited file as below: A 3 A 6 B 6 B
I have a tab-delimited text file that I am parsing. Its first column contains
Let's say I have a tab-delimited text file that contains data arranged in columns
I have a Rails 3 application with a User class, and a tab-delimited file
We have a tab delimited file that we are making available for download. The
I have a tab-delimited text file that is very large. Many lines in the
I have an ASCII file that contains tab-delimited data like this: Test_Version=2.5.3 Model-Manufacturer=D12-500 Test_Version=2.5.3
I have a huge tab separated file which I want to sort on its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.