Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have imported a shapefile that contains a serial date number that looks like this: 41256.260799. I would like to create a new field that shows only the hour and second like this: 06:33. I've tried the available VBS and Python date functions, but nothing seems to work. Would I make my new field type text? Any help appreciated.

share|improve this question
    
It would help to know how the serial date was created? Is this from excel? –  Jamie Jan 2 '13 at 16:35
    
@Gord, How are you getting 06:33 from 41256.260799. I? Do you have another example you could post? –  artwork21 Jan 2 '13 at 17:11
    
@artwork21. My mistake, I meant to type hour and minute above... from 41256.260799 I'm getting 06:15:33. I want to create a field that will display just 06:15 as a label. –  Gord Jan 2 '13 at 18:07
    
@artwork21 is based on the values that excel and other spreadsheets use. By default, January 1, 1900 is serial number 1. But becasue the OP only wants the hours and minutes they only need the fractional part. –  mhoran_psprep Jan 2 '13 at 18:11

2 Answers 2

This page is a good guide if you're asking what I think you're asking.

From here, you can get the string you want fairly easily in Python using datetime:

import datetime
new_dt = datetime.datetime(1899, 12, 30) + datetime.timedelta(days=41256.260799)
formatted_string = new_dt.time().strftime("%H:%S")

That should be pretty easy to refactor into a function for the field calculator.

share|improve this answer

But if you just need it for a label. Use it in the label expression.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.