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 would like to display a date field as a label. The data is from a shapefile. The field in question is a date field.

When I use the date field for the label, it displays in the yyyy/mm/dd format. I would like to get it to the dd/mm/yyyy format.

Is this possible. I know in MapInfo I would use the FormatDate function, I wondered whether something similar existed in QGIS.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Currently, there is work going on related to "expression based labeling": http://hub.qgis.org/issues/3488.

For now, you can use Field Calculator to convert your datetime string to a different format, e.g. YYYY/MM/DD to DD.MM.YYYY like this:

substr(date,8,2)||'.'||substr(date,5,2)||'.'||substr(date,0,4)

Substring syntax is:

substr(string,startpos,length)
share|improve this answer
add comment

If you can open the shape.dbf file in your favorite spreadsheet editor:

  • Create a new column, call it temp_date.
  • Copy and pate the old date data to temp_date
  • Split that column using text to data feature by character \ or whichever happens to be your date splitter
  • Reorganize the columns in the order you want
  • Create a new column new_date
  • In new_date use the following formula =A1 & "/" & B1 & "/" & C1. Of course you need to use the proper fields and not the ones I mentioned.

Of course there could be a default way for QGis to handle date formats, but I haven't seen it. Perhaps, play around wit the field calculator if that helps at all

I'm sure there is an option to do it using the qgis python console, I don't suspect this will be a big deal either using the time /time date modules or just a generic str.replace or reg expression. I'm not verse with the api so I can't help there

share|improve this answer
1  
It is not a good idea to edit dbf outside of a GIS program because the ObjectID field will not carry over into excel. forums.esri.com/Thread.asp?c=93&f=987&t=302104 –  artwork21 Aug 26 '11 at 14:59
    
@artwork21 - Thanks, I will delete my answer shortly. –  dassouki Aug 26 '11 at 16:06
3  
The thread referenced by @artwork21 documents a fundamental user error: when you sort the dbf, you destroy the connection between it and the features. (OID is a complete red herring; it's not used in the shapefile structure.) Provided you don't insert rows, delete rows, or reorder rows when editing the .dbf file, you'll be ok. Consider re-opening your reply in light of this. –  whuber Aug 26 '11 at 21:47
add comment

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.