# Weekly Challenge

Solve the challenge, share your solution and summit the ranks of our Community!
###### IDEAS WANTED

We're actively looking for ideas on how to improve Weekly Challenges and would love to hear what you think!

Submit Feedback
We've recently made an accessibility improvement to the community and therefore posts without any content are no longer allowed. Please use the spoiler feature or add a short message in the message body in order to submit your weekly challenge.

## Challenge #10: Date Time Calculations

Highlighted
14 - Magnetar

If I was to calculate the DateTimeDiff between the last time @SeanAdams and I raced to the finish on something, it would have been a while... until now

#SnakingMyWayThruChallenges (and starting with the easier ones, because I don't really know what I'm doing yet...)

Spoiler
Solved previously (like a million years ago) using standard Alteryx tools... this time I have done the entire thing in the Python tool.

PYTHON SCRIPT:

## INPUT DATA

# Read in various packages + Alteryx start data from input 1

from ayx import Package
import datetime
import re
import pandas

from ayx import Alteryx

## FORMAT DATA

# Define the datediff_list variable, which will become
# the list of our date differences.

# Also define the pattern that will be used in the RegEx
# expression to isolate datetime diff values.

datediff_list = list()
pattern = '(\d+)\sdays\s(\d+):(\d+):(\d+)'

# For loop to iterate through records & create a list
# for each of the desired date component values.

for i in range (len(dist_data)):

# Calculate datediff (from datetime module) using
# data in positions 1 & 2, which are datetime values.
testrecord1 = dist_data[i][1]
testrecord2 = dist_data[i][2]
diff = str(testrecord2 - testrecord1)

# Split the results of datetime diff calc from
# "n days nn:nn:nn" format into 4 columns.
diff = re.split(pattern,diff)

# Regex leaves some extra '' values in list,
# so this will remove them.
while '' in diff: diff.remove('')

# Convert the 4 list values into integers.
for n in range (0,4):
diff[n] = int(diff[n])

# Prepend original list values to the new diff list.
diff.insert(0,str(dist_data[i][2]))
diff.insert(0,str(dist_data[i][1]))
diff.insert(0,str(dist_data[i][0]))

#For each iteration, append new list to the existing list.
datediff_list.append(diff)

output = pandas.DataFrame(datediff_list)

## OUTPUT DATA

# Convert to dataframe using pandas module,
# and then rename columns.
output = pandas.DataFrame(datediff_list)
output = output.rename(columns={0: "Registrant ID", 1: "TIMESTAMP", 2: "Time_Now", 3: "Days", 4: "Hours", 5: "Minutes", 6: "Seconds"})

Alteryx.write(output,1)

Cheers!

NJ

Highlighted
8 - Asteroid

My solution

Spoiler
Could have jammed them into one tool, but left them separate for clarity.

Highlighted
6 - Meteoroid

Highlighted
8 - Asteroid

Spoiler
Highlighted
7 - Meteor

Here's my solution, thanks!

Highlighted
12 - Quasar

Revisiting in order do some #SnakingMyWayThruChallenges

I laughed

I cried

It took a long time

Highlighted
8 - Asteroid

Solution attached.

Highlighted
7 - Meteor

interesting problem, very cool problem solving.

Highlighted
12 - Quasar

On a spree to binge complete weekly challenges

Spoiler
This is my solution

Highlighted
Alteryx Partner

Challenge #10 solved. That was my 50th Alteryx Challenge