Friday, September 14, 2018

Format to Choose When Working With Date Fields Using PHP Toolkit


Question/Problem: 
 
How to make sure the value passed for standard and custom fields of type date is formatted correctly? 



Answer/Solution:
 
In PHP 5 and on, there is a predefined date format constant added that can be used with the date() function to output a string value with the right format to be imported in NetSuite. The date constant is "c" and it returns the date in the ISO 8601 format.
 
Here is  an example of a date field that can be used as the start time of a NetSuite event:

$hour = 14;
$day = 5;
$month = 3;
$year = 2011;
$startTime = date("c", mktime($hour,0,0,$month,$day,$year));
echo $startTime; 

Output:

2011-03-05T14:00:00+00:00

No comments:

Post a Comment