Search This Blog

Monday, 26 November 2012

Format DateTime into Quarter

Format DateTime into Quarter
Most of the time, we format DateTime value in various formats like day, month year etc. If we have to format a DateTime value into Quarter, we can use following expression syntax
=Format(DatePart(DateInterval.Quarter, <Date Value>))

For instance,
=Format(DatePart(DateInterval.Quarter, cdate("11/26/2012"))) will result 4.
AND
="Q"+Format(DatePart(DateInterval.Quarter, cdate("11/26/2012")))+","+cdate("11/26/2012").Year().ToString() will result Q4,2012
AND in following expression, we are going backward to 4 quarters
="Q"+Format(DatePart(DateInterval.Quarter, DateAdd(DateInterval.Quarter,-4,cdate("11/26/2012"))))+","+DateAdd(DateInterval.Quarter,-4,cdate("11/26/2012")).Year().ToString()
Will result Q4,2011

1 comment:

  1. Hey I just came through your blog its really nice. Thanks for sharing this information its very informative. Now we can easily get data in CSV format.
    historical options data

    ReplyDelete