I'm not at all experienced with writing VBScript for labeling purposes. Here is my code so far:

Function FindLabel ( [Date_of_Birth] )
  if not isnull ( [Date_of_Birth] ) then
         FindLabel = "DOB: "  &  [Date_of_Birth]
            FormatDateTime [Date_of_Birth],????
         FindLabel = ""
  end if
End Function

Basically, I want to label features that have a DOB with the DOB from the field, and if that field is null I don't want it to label. That part works great, but I noticed that some of the dates also had a time tacked on to the end. I would like to format that part out if possible. The line that reads FormatDateTime [Date_of_Birth],???? is what I found searching online, but nothing I've entered after that comma works. I'm curious if I'm on the right track or not with how I'm trying to format the date.

Thanks, Chase

  • 1
    Welcome to gis.SE. I guess you've been working on this for a while, so it probably looks pretty obvious to you, but remember that no-one else has the background that you have on your problem, so you need to provide it. For example, we know you're trying to do this in VBScript, but we'd have to guess what application (and what version of that application) you're trying to script. Can you edit your question (just click edit below the question) to provide a bit more background? Also, you can fix the formatting on your code by indenting - check the help for more on this.
    – BradHards
    Nov 6, 2013 at 20:50
  • Presumably this is with ArcGIS. What is the data source format and field type? Can you give some example values?
    – blah238
    Nov 6, 2013 at 21:06
  • @BradHards - for example, can you copy some of the [Date_of_Birth] outputs? It would be super-helpful if you could show us the correct and incorrect outputs you are getting.
    – dmsnell
    Nov 6, 2013 at 21:21
  • @dmsnell: did you possibly mean to direct this to the original poster?
    – BradHards
    Nov 6, 2013 at 22:58
  • @BradHards - yep, sorry - I meant to reply and simply refer to your post, but I wasn't thinking about it when I put your name. Thanks!
    – dmsnell
    Nov 8, 2013 at 12:30

2 Answers 2


If [Date_of_Birth] field has a fixed format for the date, you can use a combination of the LEFT(), MID(), and INSTR() functions to extract just that part.

If it's fixed-width, you can just use LEFT() to extract the first part of the string...

# [Date_of_Birth] like "1990/01/01 12:01:01 PST"
FindLabel = "DOB: " & Left([Date_of_Birth], 10)

Otherwise, you must do some dirty work to pull out the relevant portions...

# [Date_of_Birth] like "January 1, 1990, 12:01:01 PST"
Month = 1
MonthEnd = InStr([Date_of_Birth], " ") - 1
Day = MonthEnd + 2
DayEnd = InStr(Day, [Date_of_Birth], ",") - 1
Year = DayEnd + 3
YearEnd = InStr(Year, [Date_of_Birth], ",") - 1

Month = Mid([Date_of_Birth], Month, MonthEnd - Month)
Day = Mid([Date_of_Birth], Day, DayEnd - Day)
Year = Mid([Date_of_Birth], Year, YearEnd - Year)

FindLabel = "DOB: " & Month & " " & Day & ", " & Year

Since Date and Time (1990/01/01 12:01:01 PST) always has a space between use the split function. The date portion will always be in first element of array created.

arrSplit = Split(Date_of_Birth, " ")

DateOnly = arrSplit(0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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