Combining a date and time field

489
12
12-09-2019 02:04 AM
AlexRoss1
New Contributor II

Hi

I have a point shapefile with a date field, called "Date" which is a Date type field.  And I have a time field, called "Time" which is in a String format.

How can I combine these to allow me to enable the use of time for the shapefile?  The only solutions I have found are if these field are both in string format, but I am not sure how to convert the date field to string, using [Date].AsString didn't seem to work

If anyone can help that would be amazing, if possible please be very specific in your response as I am quite a beginner at this sort of stuff.

Thanks

0 Kudos
12 Replies
JoshuaBixby
MVP Esteemed Contributor

Can you elaborate on:

using [Date].AsString didn't seem to work

Did you get an error?  If so, what?  Or, were the result just unexpected, and what did you expect?

0 Kudos
AlexRoss1
New Contributor II

So I had found a possible solution but both fields had to be in String format, so was attempting to convert the Date field to a String field.  That's it really, error as follows

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Where did you get "AsString", here How To: Convert a number field to a string field ?  AsString is not a valid VB or Python function/method.

I suggest you use Python, but if you are set on using VB, then take a look at VBScript convert date to string - Stack Overflow 

JoeBorgione
MVP Esteemed Contributor

I wonder if you could use strftime() to convert your date field to a string, and then merge with your string time field, and then use strptime() to convert that whole mess back to a real live date/time value.

Are you really using shapefiles?  I thought the dbf of a shapefile didn't support a date field...

can't wait to retire....
JoshuaBixby
MVP Esteemed Contributor

Joe, the current dBASE file format supports a timestamp field:  dBASE .DBF File Structure.  That said, timestamp is new in version 7 (Beginners’ Corner (Part 2) - The dBASE Tables )

* Timestamp


New since Visual dBASE 7, Timestamp fields have a fixed width of eight bytes and are used to store the date and time of a precise moment. Note: The time precision extends to the second.

     

Esri's shapefile is based on dBASE III, which does not include a timestamp field, but a date field is supported.  So, you can store dates but not times.

JoeBorgione
MVP Esteemed Contributor

Just goes to show how often I use shape files. Years a go I responded to a post on the old forum that a friend had made.  I don't remember the exact subject, but it involed shape files. With tongue firmly planted in cheek, I posted a comment to him saying 'You know Bob, shape files are now illegal in 14 states....'  Holy cow, the frantic comments that followed...

can't wait to retire....
AlexRoss1
New Contributor II

I'll give it a try.  Thanks.  I've created a shapefile from a csv I was given.  Apologies for my lack of knowledge, I only dip in and out of GIS work, what would you otherwise use instead of a shapefile?

0 Kudos
JoeBorgione
MVP Esteemed Contributor

I use some flavor of geodatabase feature class.  Occasionally I'll export a feature class to a shape file, zip all the components up and email the zip file to a colleague. But in terms of day to day data analysis, feature classes only.

can't wait to retire....
AlexRoss1
New Contributor II

Thanks, I always thought a geodatabase was essentially a folder, and shapefiles resided within! I shall try it out

0 Kudos