function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi !
Can I know how to assign date (for example: some random date-- 24/01/1963) into a variable, in Apex.
Do we need to follow any date formats for this?
Thanks.
date x=date.newinstance(1963, 01,24); system.debug('%%%%%%'+x);
Use this .
Or if you are trying to use in test class use ..
Date x=System.today()+10; Date Y=System.today()-5;
Thanks Mohit.
My requirement was to assign sample date from test class and print in business class.
I've assigned a sample date to some date variable and sent the variable from test class and printed the date in Business class.
I could see the output. But only in year,month,day format.
Also please let me know if I can print the date in other formats..
Thanks once again..
How do you like the format to be .
Is it on visualforce Page you want the format?
No, Its not on the Visual Force page.
I am printing the outputs to log file using system.debug(). So, I want the outputs on the log file not on visual force page.
datetime x=datetime.newinstance(1963, 01,24); system.debug('%%%%%%'+x.format('yyyy-MM-dd')); system.debug('&&&&&&'+x.format('yyyy/MM/dd'));
You can use Date time and then this has a method to format .See the above code snippet
By format, I mean printing date in dd-mm-yyyy format or mm-dd-yyyy format etc..
Yes same .You can modify the above code and format that accordingly.Please find more updates
datetime x=datetime.newinstance(1963, 01,24); system.debug('%%%%%%'+x.format('yyyy-MM-dd')); system.debug('&&&&&&'+x.format('yyyy/MM/dd')); system.debug('#####'+x.format('dd-MM-yyyy')); System.debug('$$$$$$$'+x.format('MM-dd-yyyy'));
Hi ! Mohit.
Sorry for repeating the question. I will paste the code which is showing error. Please rectify the statement.
dob is variable which has date assigned from test method, which is 1960,01,20
If I print dob I get date without any errors. But only in yyyy-mm-dd format.
I've used your format function but I get the error.
"Error: Compile Error: Method does not exist or incorrect signature: [Date].format(String) at line 31 column 49"
Statement : System.debug('Employees Date of Birth:'+dob.format('yyyy-mm-dd'));
Please tell me where I've went wrong..
I have used DateTime as a Variable .Use DateTime as a Variable you will not have any exception.
If you want to use Date as Variable then you cannot use Date.format .Please see the code properly in my earlier post where i formatted .Thanks.
Also for logging purpose you may convert Date to DateTime .Use Datetime.valueOf(Date).Let me know if you need further help from me .
Use this .
Or if you are trying to use in test class use ..
Thanks Mohit.
My requirement was to assign sample date from test class and print in business class.
I've assigned a sample date to some date variable and sent the variable from test class and printed the date in Business class.
I could see the output. But only in year,month,day format.
Also please let me know if I can print the date in other formats..
Thanks once again..
How do you like the format to be .
Is it on visualforce Page you want the format?
No, Its not on the Visual Force page.
I am printing the outputs to log file using system.debug(). So, I want the outputs on the log file not on visual force page.
You can use Date time and then this has a method to format .See the above code snippet
By format, I mean printing date in dd-mm-yyyy format or mm-dd-yyyy format etc..
Yes same .You can modify the above code and format that accordingly.Please find more updates
Hi ! Mohit.
Sorry for repeating the question. I will paste the code which is showing error. Please rectify the statement.
dob is variable which has date assigned from test method, which is 1960,01,20
If I print dob I get date without any errors. But only in yyyy-mm-dd format.
I've used your format function but I get the error.
"Error: Compile Error: Method does not exist or incorrect signature: [Date].format(String) at line 31 column 49"
Statement : System.debug('Employees Date of Birth:'+dob.format('yyyy-mm-dd'));
Please tell me where I've went wrong..
Thanks.
I have used DateTime as a Variable .Use DateTime as a Variable you will not have any exception.
If you want to use Date as Variable then you cannot use Date.format .Please see the code properly in my earlier post where i formatted .Thanks.
Also for logging purpose you may convert Date to DateTime .Use Datetime.valueOf(Date).Let me know if you need further help from me .