frameworkgeek
frameworkgeek

Reputation: 213

Google SpreadSheet Custom Date Format

I'm looking for a easy formula to generate this type of Date Format:

10:35 PM August 12th 2013

hh:mm AM/PM Month dd yyyy

It's for the MarketMeSuite CSV scheduling utility that only excepts that format when uploading scheduled tweets.

Upvotes: 1

Views: 734

Answers (1)

dev
dev

Reputation: 4009

Yes this format is possible using the Utilities.formatDate() utility. Please see Oracles Class SimpleDateFormat documentation for java as this uses the same formats. You should be able to get your desired format using the below formatting.

h:mm a MMMMM d yyyy

The only issues would be with the th or nd or rd or st after the date. But you could use some if statements to format that depending on the number, I'll let you work on that :)

The final string of the above would be -

9:16 PM April 15 2013

So the final date object creation would be.

Utilities.formatDate(new Date(), "GMT", "h:mm a MMMMM d yyyy")

EDIT

I've just realised you might not be talking about getting this format in a script but actually just calling it in a cell. If so you still need to create a custom function, so add the below code to a new script.

function getDate() {
   var date = Utilities.formatDate(new Date(), "GMT", "h:mm a MMMMM d yyyy")
   return date;
}

Then you can call it back in a cell with =getDate()

Upvotes: 1

Related Questions