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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
fanninam
Creator
Creator

Subfield - Limit number of digits

I have a date field that is the following format:  'MM/DD/YYYY h:mm:ss'

I want only the 'YYYY' portion.

This statement (subfield(DateBorn,'/',3) AS DateBorn)  gives me 'YYYY h:mm:ss'

Is there a way to limit the subfield function to 4 digits so that it only gives me 'YYYY' ?

6 Replies
antoniotiman
Master III
Master III

Hi Amber,

maybe

=SubField(SubField( 'MM/DD/YYYY h:mm:ss','/',3),' ')

Regards,

Antonio

sunny_talwar

May be this

Year(Date#(DateBorn, 'MM/DD/YYYY h:mm:ss'))

Anil_Babu_Samineni

Why you need SubField over here. Can you use something like below

Year(Date#(DateFieldName,'MM/DD/YYYY hh:mm:ss'))

OR

SubField(SubField(DateFieldName, ' '),'/', -1)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
antoniotiman
Master III
Master III

However, why not

Year(DateField)

assuming Your Timestamp format is

SET TimestampFormat=MM/DD/YYYY h:mm:ss';

antoniotiman
Master III
Master III

whatever type of field , to answer  your question

"Is there a way to limit the subfield function to 4 digits"

use SubField + Left like this

Left(subfield(DateBorn,'/',3),4)

Regards,

Antonio

jmvilaplanap
Specialist
Specialist

Hi

If is a date format, and is loaded in QV as date, you can use year(DateBorn)


Regards