Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
WernerDC
Creator
Creator

Date formatting in script

Hi,

I am having trouble with converting dates to Month and year.

This is what I did:

Date#(@2) AS                       [WEATHER DATE],
Year(Date#(@2)) AS           [WEATHER YEAR], 
Month(Date#(@2)) AS      [WEATHER MONTH]

When I do list boxes, only the Date 1 displays data. Not Year nor Month shows any data?

I also tried this:

Date#(@2) AS                       [WEATHER DATE],
Year(Date(@2)) AS           [WEATHER YEAR], 
Month(Date(@2)) AS      [WEATHER MONTH]

Also no success.

 

Please advise

 

Labels (1)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

It appears your input date uses / as the separator, so you should specify:

'DD/MM/YYYY'

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

View solution in original post

4 Replies
Vegar
MVP
MVP

You should specify which format your date in @2 is stored.
If today is stored as 2019-04-16 then you should type 'YYYY-MM-DD' like below

dayname(Date#(@2,'YYYY-MM-DD')) AS [WEATHER DATE],
Year(Date#(@2,'YYYY-MM-DD')) AS [WEATHER YEAR],
Month(Date#(@2,'YYYY-MM-DD')) AS [WEATHER MONTH]
WernerDC
Creator
Creator
Author

Thank you for the response.

It however still does not work?

(Date#(@2,'DD-MM-YYYY')) AS [WEATHER DATE],
Year(Date#(@2,'DD-MM-YYYY')) AS [WEATHER YEAR],
Month(Date#(@2,'DD-MM-YYYY')) AS [WEATHER MONTH],

And 

dayname(Date#(@2,'DD-MM-YYYY')) AS [WEATHER DATE],
Year(Date#(@2,'DD-MM-YYYY')) AS [WEATHER YEAR],
Month(Date#(@2,'DD-MM-YYYY')) AS [WEATHER MONTH],

 

Please advise

 

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

It appears your input date uses / as the separator, so you should specify:

'DD/MM/YYYY'

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

WernerDC
Creator
Creator
Author

Perfect. Thank you.

 

Seems like dates can really push you around