Guest User

Untitled

a guest
Mar 21st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. "2016-05-12T23:59:11+00:00"
  2. "2016-05-13T11:00:11+00:00"
  3. "2016-05-13T23:59:11+00:00"
  4. "2016-05-15T10:10:11+00:00"
  5. "2016-05-16T10:10:11+00:00"
  6. "2016-05-17T10:10:11+00:00"
  7.  
  8. def fn(dateTime):
  9. df1=pd.DataFrame()
  10. query = """ SELECT "recordId" from "Table" where "dateTime" BETWEEN %s AND %s """ %(dStart,dEnd)
  11. df1=pd.read_sql_query(query1,con=engine)
  12. return df1
  13.  
  14. fn('2016-05-12','2016-05-15')
  15.  
  16. def fn(dStart, dEnd):
  17. query = """
  18. SELECT "recordId"
  19. FROM "Table"
  20. WHERE "dateTime" >= %(start)s AND "dateTime" < %(end)s + interval '1 day'
  21. """
  22. query_params = {'start': dStart, 'end': dEnd}
  23. df1 = pd.read_sql_query(query1, con=engine, params=query_params)
  24. return df1
  25.  
  26. import time
  27.  
  28. time_data = ["2016-05-12T23:59:11+00:00",
  29. "2016-05-13T11:00:11+00:00",
  30. "2016-05-13T23:59:11+00:00",
  31. "2016-05-15T10:10:11+00:00",
  32. "2016-05-16T10:10:11+00:00",
  33. "2016-05-17T10:10:11+00:00"]
  34.  
  35. def fn(t_init, t_fin, t_all):
  36. # Convert string inputs to struct_time using time.strptime()
  37. t_init, t_fin = [time.strptime(x, '%Y-%m-%d') for x in [t_init, t_fin]]
  38. t_all = [time.strptime(x, '%Y-%m-%dT%H:%M:%S+00:00') for x in time_all]
  39. out = []
  40. for jj in range(len(t_all)):
  41. if t_init < t_all[jj] < t_fin:
  42. out.append(jj)
  43. return out
  44.  
  45. out = fn('2016-05-12','2016-05-15', time_data)
  46. print(out)
  47. # [0, 1, 2]
  48.  
  49. %Y Year with century as a decimal number.
  50. %m Month as a decimal number [01,12].
  51. %d Day of the month as a decimal number [01,31].
  52. %H Hour (24-hour clock) as a decimal number [00,23].
  53. %M Minute as a decimal number [00,59].
  54. %S Second as a decimal number [00,61].
  55. %z Time zone offset from UTC.
  56. %a Locale's abbreviated weekday name.
  57. %A Locale's full weekday name.
  58. %b Locale's abbreviated month name.
  59. %B Locale's full month name.
  60. %c Locale's appropriate date and time representation.
  61. %I Hour (12-hour clock) as a decimal number [01,12].
  62. %p Locale's equivalent of either AM or PM.
Add Comment
Please, Sign In to add comment