0

The following is a CSV I'm working with: enter image description here

I'd like to edit all of the datetime values in this row so that it instead displays the julian date. Is this plossible?

I imagine I'll need some combination of line splitting and csv writing but I'm not sure where to start.

haramassive
  • 163
  • 1
  • 8

1 Answers1

0

This will work:

import datetime
import math

def get_julian_datetime(date):

# Perform the calculation
julian_datetime = 367 * date.year - int((7 * (date.year + int((date.month + 9) / 12.0))) / 4.0) + int(
    (275 * date.month) / 9.0) + date.day + 1721013.5 + (
                      date.hour + date.minute / 60.0 + date.second / math.pow(60,
                                                                              2)) / 24.0 - 0.5 * math.copysign(
    1, 100 * date.year + date.month - 190002.5) + 0.5

return julian_datetime

Example:

example_datetime = datetime.datetime(2015, 9, 26, 4, 30, 0)
print get_julian_datetime(example_datetime)
Rahul Agarwal
  • 4,034
  • 7
  • 27
  • 51