These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

substring of a date time stamp (first post)

dasmits
Registered: Jan 29 2010
Posts: 19
Answered

Hello, I have a date time stamp coming back from a sql db into one of my forms. I want to display only the date portion of this sting.

here is what I get:

m/d/yyyy 121212:2345
OR
mm/dd/yyyy 121212:2345

I only want the date, not the time portion coming from the DB. Is there a way to grab the string and end at the space between the date and the time?

I know I can just set the format properties inside of adobe, but that generates alot of errors for me during import process (long story)

anyways, here is what I last tried:

var dob = event.value;
if (dob.length > 10)
{
event.value = dob.indexOf (0," ");
}

Thanks in advance, I know this is probably baby stuff to you guys but I'm really struggling.

My Product Information:
Acrobat Standard 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you want to split the string on the space, do this

event.value = event.value.split(" ").shift();


If the string doesn't contain a space you'll get the whole string back and if the string is empty there won't be any errors. The only problem happens when the string is null, so you could protect the code like this

if(event.value != null)
event.value = event.value.split(" ").shift();


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

dasmits
Registered: Jan 29 2010
Posts: 19
Hi Thom! thank you so much! that worked like a charm. you can bet that I'm already carving out some time to peruse the links from your post :-) now on to these pesky radial buttons :-)