Concatenate two strings in a DateTime


I have a text file that contains two fields , one for the date and one for time . Each fields is stored in a variable.

I want to concatenate these two variables and put it in SalesTable.CreatedDatetime.

I have tried : str2datetime(date1+’’+date2,123) but it doesn’t work.

Can you help me, please ?


Hi Marc,

Please check the date and time format in the text file.

If the date and time format is correct then, str2datetime will work perfectly. Please refer this link

For example:

str2datetime(‘21/01/2014 10:00:00’, 123)

seconds is required.

You can also use date time util. For example:

DateTimeUtil::newDateTime(1\1\2014, str2time(‘10:00’))



Check if the string values are valid,

createdDateTime is a system field, this can be overwritten during the insert.

See \Classes\IntercompanySyncNotesTask\writeDocuRef

It all depends on the format; unfortunately all what we can say so far is that your format isn’t valid for str2datetime().

Either modify the string to a valid format, or use a more clever way for parsing strings to date and time, such as System.DateTime::ParseExact().

An alternative solution would be parsing date and time separately and putting them together by DateTimeUtil::newDateTime().

The format for the date is dd/mm/yyyy

and the format for the time is : hh:mm

As you already found, dd/mm/yyyyhh:mm isn’t a format supported by str2datetime(). This is how you need to transform your data, if you want to use str2datetime():

str dateStr = '31/12/2015';
str timeStr = '12:34';
str s =  strFmt("%1 %2:00", dateStr, timeStr);
utcDateTime dt = str2datetime(s, 123);

Thanks a lot guys !

Your solution works well in a job, Martin but it doesn’t work in my class. I think so we can’t modified SalesTable.createdDateTime as says Kranthi.

You’re mixing two separate things. My solution works correctly; that you’re using the value for a wrong purpose has nothing to do with my conversion from string to datetime.

I didn’t comment on CreatedDateTime field, because it was already said above.