2

I have a custom date field and a picklist field for time (holding values eg. 00:00 00:15 etc). I want to concatenate them into a single dateTime variable. currently I am using this :

dateTime newDateTime = DATETIMEVALUE(string.valueOf((ac.Start_Date__c.year())) +'-'+ string.valueOf(ac.Start_Date__c.month())+'-'+ string.valueOf(ac.Start_Date__c.day())+' ' + string.valueOf(ac.Start_Time__c) +':00');

But its not working. It is saying :

Compile Error: Method does not exist or incorrect signature: DATETIMEVALUE(String) 

Any help would be appreciated

2 Answers 2

2

You can't use "formulas" in Apex Code. Instead, use the DateTime constructors. You might do something like this:

DateTime startDateTime = DateTime.newInstance(
    ac.Start_Date__c, 
    Time.newInstance(
        Integer.valueOf(ac.Start_Time__c.split(':')[0]),
        Integer.valueof(ac.Start_Time__c.split(':')[1]), 
    0, 0));
0
1

You can use:

strDate = string.valueOf(Start_Date__c);

strTime = string.valueOf(Start_Time__c);

strDateTime = strDate + ' ' + strTime;

newDateTime = DateTime.valueOf(strDateTime);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .