htmanning has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to parse through a timestamp and set each piece to a variable so I can compare the date. I grab the timestamp out of the database, then compare it to $now to see if I should display certain data. The issue I'm having is if the date number (1-31) is a single digit number, there is an extra space before the actual number and the below doesn't work correctly. This also happens if the time starts with a single digit number. I'm not sure how to solve this. In other words, if the timestamp is Mon May 9, 2020 - 11:11:11 the $this_date var is empty and the $this_year var become the date number (9).
$timestamp = $dt->strftime("%a %b %e, %Y - %k:%M:%S"); #timestamp in +the database like this @timestamp = split (/ /, $timestamp); $this_day = "@ timestamp[0]"; $this_month = "@ timestamp[1]"; $this_date = "@ timestamp[2]"; $this_year = "@ timestamp[3]"; $this_dash = "@ timestamp[4]"; $this_time = "@ timestamp[5]";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing Timestamp with extra spaces
by choroba (Cardinal) on May 11, 2020 at 23:20 UTC | |
|
Re: Parsing Timestamp with extra spaces
by perlfan (Parson) on May 12, 2020 at 02:16 UTC | |
|
Re: Parsing Timestamp with extra spaces (updated)
by AnomalousMonk (Archbishop) on May 12, 2020 at 02:22 UTC | |
|
Re: Parsing Timestamp with extra spaces
by Anonymous Monk on May 11, 2020 at 23:19 UTC | |
|
Re: Parsing Timestamp with extra spaces
by johngg (Canon) on May 12, 2020 at 13:45 UTC | |
|
Re: Parsing Timestamp with extra spaces
by Marshall (Canon) on May 14, 2020 at 09:37 UTC |