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 a Date column in my feature class and I want the date to appear in "dd MMM yyyy" format as a label to a polygon. I am using Arc Map 10.1. I tried taking Jscript.

var Dt  = new Date();
Dt = Dt.toString("dd MMM yyyy");

But it gives error. I can implement the solution in jscript ,vbscript and python if available.

share|improve this question
    
You're asking too much in one question here and it's unclear what you want. Do you just want somebody to your JScript? –  Jason Scheirer Aug 19 '13 at 16:03

2 Answers 2

There are links to each language Reference pages at the bottom of this esri help page.

If you are writing a function you should check the advanced box and as described write in the selected language of the parser (below).
label dialog

share|improve this answer
    
I am doing that but I am not finding any built In function to Format date because if it support Jscript then it should execute above statements. –  Gunner Aug 19 '13 at 14:42
    
Your statements are being executed but the output is not what you expect, nor should it be. While you can produce a string representation of Date objects with the toString() method, you cannot pass a format string and get a formatted Date string See the documentation on toString(). My answer below describes how you can format your Date strings with JScript. –  Arthur Oct 31 '13 at 14:19

It would be helpful to know the error that you are getting. I imagine it reads, "Carriage returns are not allowed in simple expressions," meaning that your label expression has to fit on one line. The expression you provided can be easily changed to fit on one line:

new Date().toString();

Note that I removed your argument to toString(). It wasn't doing anything for you. JavaScript Date objects inherit the toString() method from the Function object and this method does not take any arguments. If you're looking for a way to format your date string, try one of these methods on your date instance. You'll probably have to do some string manipulation, as JavaScript (or "JScript") does not have good native support for formatting timestamps.

To create the timestamp you're looking for, check the "Advanced" box in the label expression editor and enter the following:

function FindLabel( )
{
    var d = new Date();
    var z = (d.getMonth() < 9) ? '0' : '';
    return d.getDate() + ' ' + z + (d.getMonth() + 1).toString() + ' ' + d.getFullYear();
}

Note that this should provide you with a zero-padded month (via the test that sets the z variable) and that getMonth() returns a number that is 1 less than you would expect (as the number of the month is zero-indexed).

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.