CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Date and time format

 



ogit2
Novice

Mar 23, 2018, 4:09 AM

Post #1 of 3 (5838 views)
Date and time format Can't Post

Hi

I have data come in that I need to extract the date and first time and then update the system by calculating one day prior. I can easily do the one day prior calculation so that part is not a problem.

Unfortunately this data is entered by our customer as free text. I am not going to embarrass myself by entering the code I have used so far to extract date and time as it is too convoluted and fails 10% of the time.

I don't believe there is a solution that would cope with the sample data listed below (results required after arrow -->). The experts here may have an idea to use some sort of AI (never done this in Perl - Any modules need to compile with Active state) so any pointers would be appreciated.

If I am asking the impossible, let me know.



Code
26.03.2018 @ 08:00 ref 63025 --> 26/03/2018 08:00 
26.03.2018 9am - 16:00 Fay *15ft -> 26/03/2018 09:00
25.03.2018 @ ref 1435 06:00 -> 25/03/2018 06:00
23 03 1500 ref 61436 -> 23/03/2018 15:00
fyi 2134 24/03/2018 at 4pm WP0507 -> 23/03/2018 16:00
ref 201825 at 05:04 on 25/03/2018 ref FAY -> 25/03/2018 05:04
25/03/2018 at 06:0 -> 25/03/2018 06:00
26.03.20018 4 pm 11386902* -> 26/03/2018 04:00
26.03.18 @ 20.30 -> 26/03/2018 20:30
26.03.2018 @ 23.30 ref 2234 -> 26/03/2018 23:30
26/03/2018 at 06:04 -> 26/03/2018 06:04
26.03.2018 @ 07.45 Ref RCB/26/21 -> 26/03/2018 07:45
26/03/2018 at 19:40 -> 26/03/2018 19:40
26/03/18 at 18:00 -> 26/03/2018 18:00
26 March 2018 1800 (6pm) -> 26/03/2018 18:00
26/03/2018 for 22:00 -> 26/03/2018 22:00
26 3 18 @ 14:00 ref 63026 -> 26/03/2018 14:00
26.03.2018 @ 19:00 ref 63027 -> 26/03/2018 19:00



(This post was edited by ogit2 on Mar 23, 2018, 4:29 AM)


BillKSmith
Veteran

Mar 23, 2018, 8:26 AM

Post #2 of 3 (5829 views)
Re: [ogit2] Date and time format [In reply to] Can't Post

The module Date::Calc is the "Swiss Army Knife" of Date and time calculations. It is rarely the best choice, but it almost always does the job. In your case, I think that you want its function "Decode_Date_EU". If this is a problem, you could search CPAN for a similar function in another module.
Good Luck,
Bill


Laurent_R
Veteran / Moderator

Mar 25, 2018, 11:25 PM

Post #3 of 3 (5799 views)
Re: [ogit2] Date and time format [In reply to] Can't Post

I don't think it is a problem for AI, it is more a problem for a parser. But this might be overkill.

Otherwise, a possibility would be to roll out a series of reguar expressions, e.g. one per possible input format.

But the real solution might be to force the user to enter the right (i.e. expected) format by asking her or him to enter one piece of data at a time, such the day, then the month, then the year, then the time of day.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives