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
Tell me how to get only date from a value or how to delete time from this format.
2011-09-20 00:00:00
thanks
Anuraj
If you have the value in a string then use
String s='2011-09-20 00:00:00'; string a=s.substring(0,10); Date d=date.valueof(a);
or
if its stored in a datetime field
date.valueof(a)
where a is a datetimefield
i havent tested them, these should work i guess
When it is in string type then it is 2011-09-20 format
afrer when it is converted to date then it comes in this format 2011-09-20 00:00:00.
anuraj
Hi Anuraj
You can create a DateTime instance and then using string change the format like I did and got only the Date.
Try this.
// Create DateTime Instance
Datetime CurrentDateTime= system.now();
system.debug('System.now :'+myDate1 );
// Trim to get Date value
String myDat = CurrentDateTime.format('dd/MM/yyyy');
system.debug('After Concatenation :'+myDat );
Regards,
Zubair
Hi Zubair
I am gettig this error
Compile Error: Method does not exist or incorrect signature: trim(Date)
Hi Anuraj,
You want to get the Date in DateFormat or StirngFormat?
Zubair.
I want to get the date format but don't want time in it.
I am getting 2011-09-20 00:00:00
I don't want time in it and want it as 2011-09-20
my code is
if (!StartDate.equals('')) myDate = date.valueOf(StartDate);
soql += ' and Start_Date__c = ' + myDate;
This worked for me:
String s='12/27/2009 6:46 AM'; string a=s.substring(0,10); Date d=date.parse(a); system.debug('======'+database.query('Select Id, Name from Account where Createddate > :d'));
Try:
soql += ' and Start_Date__c = :myDate';
If you have the value in a string then use
or
if its stored in a datetime field
date.valueof(a)
where a is a datetimefield
i havent tested them, these should work i guess
Hi
When it is in string type then it is 2011-09-20 format
afrer when it is converted to date then it comes in this format 2011-09-20 00:00:00.
thanks
anuraj
Hi Anuraj
You can create a DateTime instance and then using string change the format like I did and got only the Date.
Try this.
// Create DateTime Instance
Datetime CurrentDateTime= system.now();
system.debug('System.now :'+myDate1 );
// Trim to get Date value
String myDat = CurrentDateTime.format('dd/MM/yyyy');
system.debug('After Concatenation :'+myDat );
Regards,
Zubair
Hi Zubair
I am gettig this error
Compile Error: Method does not exist or incorrect signature: trim(Date)
thanks
Anuraj
Hi Anuraj,
You want to get the Date in DateFormat or StirngFormat?
Regards,
Zubair.
I want to get the date format but don't want time in it.
I am getting 2011-09-20 00:00:00
I don't want time in it and want it as 2011-09-20
my code is
thanks
Anuraj
This worked for me:
Try: