You need to sign in to do that
Don't have an account?
Vasco SIlveiro
Convert number to string without losing the zero
Hey ,
I´ve create a buttom where it creates a password based on the birthday of my account (YYYYMMDD) , the problem is that when we the day/month as a zero its ignored . Any one has a solutions:
Eg: Birthday : 1992/05/09
Password : 199259 instead of 19920509
This is the code
if( resultados != null && resultados.size() > 0){
for(Account result: resultados){
result.Username__c = result.NIF__c;
result.Password__c = ''+result.PersonBirthdate.day() + result.PersonBirthdate.month() + result.PersonBirthdate.year();
}
}
Thank u in advanced
I´ve create a buttom where it creates a password based on the birthday of my account (YYYYMMDD) , the problem is that when we the day/month as a zero its ignored . Any one has a solutions:
Eg: Birthday : 1992/05/09
Password : 199259 instead of 19920509
This is the code
if( resultados != null && resultados.size() > 0){
for(Account result: resultados){
result.Username__c = result.NIF__c;
result.Password__c = ''+result.PersonBirthdate.day() + result.PersonBirthdate.month() + result.PersonBirthdate.year();
}
}
Thank u in advanced
It will look like this:
for(Account result: resultados){
String bday = (result.PersonBirthdate.day()>=10)?''+result.PersonBirthdate.day()):'0'+result.PersonBirthdate.day();
String mo = (result.PersonBirthdate.month()>=10)?''+result.PersonBirthdate.month()):'0'+result.PersonBirthdate.month();
result.Username__c = result.NIF__c;
result.Password__c = bday + mo + result.PersonBirthdate.year();
}
All Answers
It will look like this:
for(Account result: resultados){
String bday = (result.PersonBirthdate.day()>=10)?''+result.PersonBirthdate.day()):'0'+result.PersonBirthdate.day();
String mo = (result.PersonBirthdate.month()>=10)?''+result.PersonBirthdate.month()):'0'+result.PersonBirthdate.month();
result.Username__c = result.NIF__c;
result.Password__c = bday + mo + result.PersonBirthdate.year();
}
Here is modified code::
if( resultados != null && resultados.size() > 0){
for(Account result: resultados){
result.Username__c = result.NIF__c;
string d = result.PersonBirthdate.day()+'';
string m = result.PersonBirthdate.month()+'';
string y = result.PersonBirthdate.year()+'';
if( m.length() == 1 )
m='0'+m;
if( d.length() == 1 )
d='0'+d;
result.Password__c = d+''+m+''+y;
}
}
:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....
This one seems more simple and respond to the requirement (password = yyyymmdd): I've tried using constant values, not using date methods, but should works too.
Here what I've tested: Hope this helps,
Fred