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]";
In reply to Parsing Timestamp with extra spaces by htmanning
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |