We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › convert string (or int) to DATE
Page Index Toggle Pages: 1
convert string (or int) to DATE? (Read 554 times)
convert string (or int) to DATE?
Mar 21st, 2006, 7:37pm
 
Is this possible?

20060315 is in my database. Can 'processing 108+' read this as yyyymmdd?
How to convert to year() month() day() or something?

{TypoVar}
Re: convert string (or int) to DATE?
Reply #1 - Mar 21st, 2006, 8:07pm
 
try:
Code:

String date = "20060325";
char[] date_c = date.toCharArray();
String year = new String( new char[]{date_c[0], date_c[1], date_c[2], date_c[3]} );
String month = new String( new char[]{date_c[4], date_c[5]} );
String day = new String( new char[]{date_c[6], date_c[7]} );

println( year + " - " + month + " - " + day );
Re: convert string (or int) to DATE?
Reply #2 - Mar 21st, 2006, 8:09pm
 
You can do it manually farily easily, for example:

Code:
String date="20060315";
int Year=int(date.substring(0,4));
int Month=int(date.substring(4,6));
int Day=int(date.substring(6,8));
println("Year: " + Year +", Month: "+ Month + ", Day: "+Day);
Re: convert string (or int) to DATE?
Reply #3 - Mar 21st, 2006, 8:13pm
 
you can also use the Java "Date" object to parse dates of any format, but i like johng's solution better, much more straightforward for this particular case.
Re: convert string (or int) to DATE?
Reply #4 - Mar 22nd, 2006, 7:46am
 
Thanks very much.
There is no "DATE.format" short- or long-format to convert
"20060322" to "Wednesday, March, 22, '03"
Re: convert string (or int) to DATE?
Reply #5 - Mar 22nd, 2006, 3:11pm
 
yep, you can make your own custom date format, which is usually what you have to do for that stuff. but like i said, johng's solution is much more straightforward.
Page Index Toggle Pages: 1