0

This is what I have:

var data_week_1_raw = selectTheSheet.getRange(1,3).getValue();
Logger.log(data_week_1_raw);
var data_week_1 = Utilities.formatDate(new Date(data_week_1_raw), "CST", "MMM DD YYYY");
Logger.log(data_week_1);

This is what it's outputting:

9:54:43 AM  Info    Mon Aug 15 00:00:00 GMT-05:00 2022
9:54:43 AM  Info    Aug 227 2022

Anybody have any idea what's going on here? How to fix it?

I've tried looking around the www but really haven't seen this issue anywhere else. I've tried redundant formatting or changing time zones between formats (ie. GMT-5 or CST)... nothing really changes this result thus far.

Other solutions that the workflow bot thinks are the same but are not
Google Apps Script date format issue (Utilities.formatDate) talks about trying to get a certain format output FROM a script into the google sheets. This does not at all resemble what I am having an issue with.

Utilities.formatDate returning wrong week number describes a problem where the data being pulled from the sheet is not appearing properly... this does not use the same function and again is not the issue I am experiencing.

danw
  • 3
  • 2
  • 1
    `D` is day in year. `d` is date. Also should be `yyyy` – TheWizEd Nov 05 '22 at 15:39
  • From [Tainake's answer](https://stackoverflow.com/a/51904773/1595451) "`Y` is used as Week year. So please modify to `y`". – Rubén Nov 05 '22 at 15:41
  • Also, when looking for help on code that is not working, include a [mcve], add some sample data, in this case the Google Sheets cell add the cell displayed value and the data type as logging the value returned by `getValue()` will show something different to what is shown in the Google Sheets UI hidding some underlying problems. – Rubén Nov 05 '22 at 15:47
  • 1
    Thank you, this all makes sense and has solved my issue. I am not sure I would have been able to find answers relating to the case of the letters... not knowing what the problem source is. Thank you for these clarifications! I would accept these answers, however, I don't have the option :( Rubén, thank you for the feedback. I will remember that. I guess because I hadn't seen an issue with that portion I didn't think to add it. Thanks all! – danw Nov 05 '22 at 15:50
  • 2
    Here is a list of all [date format characters](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) – TheWizEd Nov 05 '22 at 17:43

0 Answers0