Get date format from field

Contributor ,
Jun 19, 2017

Copy link to clipboard

Copied

I want to be able to get a date object form a date field. I am aware I can do this:

var value = getField("date").value;

var date = util.scand("yyyy-mm-dd", sDate);

But this requires that I know what the date format is.

I want to be able to get a date object from a date fields without having to bake the formatting string into the script.

Any help would be appreciated

TOPICS
Acrobat SDK and JavaScript

Views

747

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Get date format from field

Contributor ,
Jun 19, 2017

Copy link to clipboard

Copied

I want to be able to get a date object form a date field. I am aware I can do this:

var value = getField("date").value;

var date = util.scand("yyyy-mm-dd", sDate);

But this requires that I know what the date format is.

I want to be able to get a date object from a date fields without having to bake the formatting string into the script.

Any help would be appreciated

TOPICS
Acrobat SDK and JavaScript

Views

748

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 19, 2017 0
Most Valuable Participant ,
Jun 19, 2017

Copy link to clipboard

Copied

Not possible.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Adobe Community Professional ,
Jun 19, 2017

Copy link to clipboard

Copied

You can try:

var date = new Date(Date.parse(sDate));

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Most Valuable Participant ,
Jun 19, 2017

Copy link to clipboard

Copied

Without knowing the format any parsing method is useless. How would it know if "01-03-16" is January 3rd 2016, or March 1st 2016, or March 16th 2001 or March 16th 1901, etc.?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Adobe Community Professional ,
Jun 19, 2017

Copy link to clipboard

Copied

It works for the format yyyy-mm-dd.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Most Valuable Participant ,
Jun 19, 2017

Copy link to clipboard

Copied

I want to be able to get a date object from a date fields without having to bake the formatting string into the script.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Adobe Community Professional ,
Jun 19, 2017

Copy link to clipboard

Copied

For my solution you don't need the format string "yyyy-mm-dd".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Most Valuable Participant ,
Jun 19, 2017

Copy link to clipboard

Copied

It's still "baked" into the preassumptions the Parse method is making, though, so in effect it's the same.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Adobe Community Professional ,
Jun 19, 2017

Copy link to clipboard

Copied

You can use the JavaScript Date object to parse your date string:

var sDate = getField("date").value; 

var newDate = new Date(Date.parse(sDate));

You can find details about how this works here: Date.parse() - JavaScript | MDN

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Contributor ,
Jun 19, 2017

Copy link to clipboard

Copied

the only thing that seems to differentiate a date picker field and a text field is the built in date format option.

Is there a way that I could call the built in date formatting action from within a custom format script allowing me to specify the format while still displaying the field as a date picker?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0
Adobe Community Professional ,
Jun 19, 2017

Copy link to clipboard

Copied

You'll need to create two separate fields one with the custom format and one with the date format. Then you just have them update each other via a script.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2017 0