I am writing a script for automating XML data in Indesign. I currently have in the XML the date in American Format (MM/D/YY) but once I run the script in Indesign my goal is to have it be in European format (DD/M/YY). What can I add to my script in order to write a function that will convert any date formats to european formats? I hope this makes sense. I need help!
Asked
Active
Viewed 1.7k times
3 Answers
3
i guess simply using
function convertDate(dateString) {
var date = new Date(dateString);
return date.getDate()+"/"+(date.getMonth() + 1)+"/"+date.getFullYear();
}
just note european format does not use slashes but dots as far as i know so it should look like this dd.mm.yyyy not dd/mm/yyyy becouse it can be mismatched with us format

Stephen Horvath
- 5,188
- 3
- 24
- 31

derki
- 620
- 3
- 7
-
hmmm I added that at the end of my script and it isnt updating the dates - i will warn you i appreciate all this help but im so clueless..this was not in my job description haha – Aug 15 '12 at 14:42
-
its a function you need to call this function at desired point to make it work, i dont know how actually your source code for this looks like so i cant tell you exactly – derki Aug 15 '12 at 14:47
-
yea i dont even know where to begin this is frustrating. maybe i can smile my way out of this one lol. but is it even possible to do this. so in the XML it read (11/27/12) for example. but it changes every month but we have a generic script that does all the rounding of numbers and stuff. haha i sound so dumb right now i dont even know what to say ill stop wasting your time :) – Aug 15 '12 at 14:52
-
so you should have already something working which is iterating those data and working with them right? – derki Aug 15 '12 at 14:56
-
yep - but we don't want to have to manipulate the xml date every month. so it comes in from the data mart in american format. but we would like the European format once the script is ran. – Aug 15 '12 at 14:58
-
well then you should alter those dates directly in your XML via script and then save it with eu format, is this you looking for? – derki Aug 15 '12 at 15:06
-
Our goal is to not have to edit the XML every month. We get mass amounts of date..we import the XML in a document and then run a script and it does all the rounding/converting etc we need for the documents. So basically i suck and idk what im doing lol but you're a dear for trying to help :) – Aug 15 '12 at 15:09
-
add script i gave you to that rounding and converting process – derki Aug 15 '12 at 15:17
-
You need to add 1 to the month since it starts at 0-index. – Stephen Horvath Jun 05 '20 at 15:12
2
How to format a JavaScript date?
Return dd-mm-yyyy from Date() object
var d = new Date().toLocaleDateString("uk-Uk");
Output: 03.09.2021
var d = new Date().toLocaleDateString("en-GB");
Output: 03/09/2021
var d = new Date().toLocaleDateString("en-UK").replace(/\//g, '-');
Output: 03-09-2021

Stefan27
- 845
- 8
- 19
0
var myDate = new Date('myDateString'); //you can also do milliseconds instead of the date string
var myEuroDate = myDate.getDate() + '/' + myDate.getMonth + '/' + myDate.getFullYear();
Useful as well... http://arshaw.com/xdate/

mattnull
- 342
- 2
- 9
-
How about http://www.w3schools.com/jsref/jsref_obj_date.asp ... you can use the javascript Date object to construct your date string – mattnull Aug 15 '12 at 14:29
-
-
-
I just am not good @ javascript and automating in Indesign..so im struggling lol but i want to solve this. Do I just add at the end of the script? basically I want (MM/DD/YY) to convert to (DD/MM/YY) anytime it appears in the document? – Aug 15 '12 at 14:33
-
It would be helpful, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat – Behrouz Pooladrak Jul 09 '21 at 11:54