Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

month & year from date

Hi Experts

Hoe can I script to receive a month and a year out of a field containing a date? I tried the following which did not work:

SQL SELECT jobnr,

    datum,

    Month (datum)& Year (datum) as StundenMonat,

    stunden,

    stundenart,

    marnr as MitarbeiterStunden

FROM EASY.stunden;

I would like to have: 01 2014, 02 2014 e.g.

Thank you for your help!

Jan

1 Solution

Accepted Solutions
MarcoWedel

or better

LOAD *,

        Date(MonthStart(datum),'MM YYYY') as StundenMonat;

SQL SELECT jobnr,

    datum,

    stunden,

    stundenart,

    marnr as MitarbeiterStunden

FROM EASY.stunden;

because this will create a real date instead of text, i.e. no sorting and calculation issues ...

regards

MArco

View solution in original post

8 Replies
sunny_talwar

I wonder why it did not work. But Try this instead.

Month(Date(datum))& ' ' & Year(Date(datum)) as StundenMonat


This may or may not work, but worth giving a shot.


Best,

S

agomes1971
Specialist II
Specialist II

Hi,

maybe  Month (datum)&' '& Year (datum) as StundenMonat

HTH

André Gomes

kamal_sanguri
Specialist
Specialist

Hi,

You can use month and year function to take out the respective part from Date.

For Ex: if you want to pull number of the month you can try

numsum(month(DateField)) & Year (DateField)

Thanks,

kamal

Not applicable
Author

Check whether datum is in date format . If yes then try onth (datum)&' '& Year (datum)

MarcoWedel

you're mixing QV script with SQL.

Try

LOAD *,

         Month (datum)& Year (datum) as StundenMonat;

SQL SELECT jobnr,

    datum,

    stunden,

    stundenart,

    marnr as MitarbeiterStunden

FROM EASY.stunden;

MarcoWedel

or better

LOAD *,

        Date(MonthStart(datum),'MM YYYY') as StundenMonat;

SQL SELECT jobnr,

    datum,

    stunden,

    stundenart,

    marnr as MitarbeiterStunden

FROM EASY.stunden;

because this will create a real date instead of text, i.e. no sorting and calculation issues ...

regards

MArco

sunny_talwar

Good catch. Did not see that.

Not applicable
Author

True Thank you!