[GIS] ArcGIS 10, Converting from date to number

arcgis-10.0

I am trying to transform a date field like "00:05:40" into an integer field (i.e. 340 sec).
Does anyone know how I could do that conversion please?

Best Answer

you can use arcpy UpdateCursor function for updating your field.

Summary

The UpdateCursor function creates a cursor that lets you update or delete rows on the specified feature class, shapefile, or table. The cursor places a lock on the data that will remain until either the script completes or the update cursor object is deleted.

Syntax

UpdateCursor (dataset, {where_clause}, {spatial_reference}, {fields}, {sort_fields})

import arcpy

rows = arcpy.UpdateCursor("C:/myData.gdb/times") 

for row in rows:  
    date = row.DATE # 00h05min40sec
    dat = date.split('h')
    hour = dat[0] # 00
    min = dat[1].split('min')[0] # 05
    sec =  dat[1].split('min')[1].split('sec')[0] # 40
    newDate = hour * 3600 + min * 60 + sec # 340
    row.DATE = newDate
    rows.updateRow(row) 

del row 
del rows

i hope it helps you...

Related Question