I am using the below code and the data I am gettin...
# suitescript
r
I am using the below code and the data I am getting is throwing an error in a date field. basically I want to get the week start date in MM/DD/YYYY format.
Copy code
function startOfWeek()
        {
            current_date =  new Date();
            var diff = current_date.getDate()-current_date.getDay()+(current_date.getDay() === 0 ? -6 : 1);
            var date = new Date(current_date.setDate(diff));
            var WSD = format.format({
                value: date,
                type: format.Type.DATE
            });
            return WSD;
        }
and even though the log.debug shows a string in MM/DD/YYYY format its still throwing an error. Have tried multiple snippets for the same task and none of them is returning a value that can be put in the date field of the record.
b
use setValue with a Date object
use setText with a string
i would also be very weary of timezone errors, your code has a chance of being off by a day during certain hours if the timezone of the user is not Pacific
r
time zone is not the issue right now. By the way I used setText and it still throwed an error. I am passing the date in the date field.
b
the parameters to Record.setText are not the same as Record.setValue
r
yeah my bad, thank you. one last question If I wanted to use setValue instead of setText Is there a way to convert the string back to a date object but keep the date format in MM/DD/YYYY.
b
wrong way of thinking about dates
they dont have format. strings representing dates have formats
dates represent a number (time since unix epoch)
r
true I guess, its just when we used to print the date it gives us a datetime object Instead of the value in milliseconds. so I thought we could change the formatting. anyway thank you.
b
if you wanted to use setValue, you would simple use
date
or honestly
current_date
they are both the same Date
r
date is giving me start of the week for today its same. as currently in UTC today is monday. tomorrow both will be different. current_date will be of tuesday. while date will show as monday
b
im not saying that either is really correct due to my timezone warning
but after
var date = new Date(current_date.setDate(diff));
they are the same Date
setDate behaves a little weird for a setter in that it both returns unix time and modifies the date