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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Time conversions

I have a datetime field Startime which is in GMT and has to be converted to PST ,

Here is my Load statement , how do i convert to PST in load statement ?

Load

starttime

,

Date

,

Week

(starttime) AS [Week #]

,

WeekStart

(starttime) as Week

,

Year

(starttime) AS Year

,

Month

(starttime) AS [Month #]

,

MonthStart

(starttime) as Month

,

Day

(starttime) AS [Day]

,

Weekday

(starttime) AS WeekDay

,

Date

(monthstart(starttime), 'MMM-YYYY')

AS

MonthYear

,

Week

(starttime)&'-'&Year(starttime) AS WeekYear

,

hour

(starttime) as BuildHour







19 Replies
Anonymous
Not applicable
Author

One note: conversion to Date must be done after convertion from GMT to local time.

Anonymous
Not applicable
Author

This is my current script

LOAD

Week(starttime) AS [Week #],
WeekStart(starttime) as Week,
Year(starttime) AS Year,
Month(starttime) AS [Month #],
MonthStart(starttime) as Month,
Day(starttime) AS [Day],
Weekday(starttime) AS WeekDay,
Date(monthstart(starttime), 'MMM-YYYY') AS MonthYear,
Week(starttime)&'-'&Year(starttime) AS WeekYear,
hour(starttime) as BuildHour,
BuildSizeMB,BuildID,
Action,Duration,FileCount,ProductLine,Duration_Min,
UserName,JobName,Date


;

Load
converttolocaltime(starttime,'Pacific Time (US & Canada)') as starttime,
BuildSizeMB,BuildID,
Action,Duration,FileCount,ProductLine,Duration_Min,
UserName,JobName,Date

;

SQL select starttime,CONVERT(VARCHAR(10),starttime,101) AS Date,BuildID,
((bytecount)/1024/1024) as BuildSizeMB,(DURATION/60)AS Duration_Min,
Action,Duration,FileCount,ProductLine,SubmittedBy as 'UserName',JobName
FROM ASWTRANS.DBO.CRMBUILDMETRICS

Do you think it should be something like below ? , But i get an syntax error saying converttolocaltime is not identfied, One basic question , how do the select statement work here , i got an idea of load statements loading , when does a select statement come into consideration ?before or after load statement?

LOAD

Week(starttime) AS [Week #],
WeekStart(starttime) as Week,
Year(starttime) AS Year,
Month(starttime) AS [Month #],
MonthStart(starttime) as Month,
Day(starttime) AS [Day],
Weekday(starttime) AS WeekDay,
Date(monthstart(starttime), 'MMM-YYYY') AS MonthYear,
Week(starttime)&'-'&Year(starttime) AS WeekYear,
hour(starttime) as BuildHour,
BuildSizeMB,BuildID,
Action,Duration,FileCount,ProductLine,Duration_Min,
UserName,JobName,Date


;

Load
converttolocaltime(starttime,'Pacific Time (US & Canada)') as starttime,
BuildSizeMB,BuildID,
Action,Duration,FileCount,ProductLine,Duration_Min,
UserName,JobName,Date

;

SQL select starttime,CONVERT(VARCHAR(10),converttolocaltime(starttime,'Pacific Time (US & Canada)') ,101) AS Date,BuildID,
((bytecount)/1024/1024) as BuildSizeMB,(DURATION/60)AS Duration_Min,
Action,Duration,FileCount,ProductLine,SubmittedBy as 'UserName',JobName
FROM ASWTRANS.DBO.CRMBUILDMETRICS

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


RAMYA_BEGINNER wrote:But i get an syntax error saying converttolocaltime is not identfied, One basic question , how do the select statement work here , i got an idea of load statements loading , when does a select statement come into consideration ?before or after load statement?


ConvertToLocalTime is a QV function. It must be used in the LOAD statement, not in the SQL Select. Only valid SQL may be used in the SQL Select.

The SQL Select is executed first. The data returned by the SQL Select is "passed up" to the LOAD statement.

-Rob

Anonymous
Not applicable
Author

I changed my Script to below , but i am getting all duplicate values for date, to avoid this i used convert function in select statement previously , as converttolocaltime cannot be used in sql statement and convert(which converts datetime value to date in 101 form) cannot be used in load statement i cannot understand how to go with this...

By the way how do i attach a qlikview file to my post , i tried using insert media , did not work ...

Please Help..


LOAD

Week(starttime) AS [Week #],
WeekStart(starttime) as Week,
Year(starttime) AS Year,
Month(starttime) AS [Month #],
MonthStart(starttime) as Month,
Day(starttime) AS [Day],
Weekday(starttime) AS WeekDay,
Date(starttime) as Date,
Date(monthstart(starttime), 'MMM-YYYY') AS MonthYear,
Week(starttime)&'-'&Year(starttime) AS WeekYear,
hour(starttime) as BuildHour,
BuildSizeMB,BuildID,
Action,Duration,FileCount,ProductLine,Duration_Min,
UserName,JobName


;

Load
converttolocaltime(starttime,'Pacific Time (US & Canada)') as starttime,
BuildSizeMB,BuildID,
Action,Duration,FileCount,ProductLine,Duration_Min,
UserName,JobName

;

SQL select starttime,BuildID,
((bytecount)/1024/1024) as BuildSizeMB,(DURATION/60)AS Duration_Min,
Action,Duration,FileCount,ProductLine,SubmittedBy as 'UserName',JobName
FROM ASWTRANS.DBO.CRMBUILDMETRICS

boorgura
Specialist
Specialist

Hey Ramya,

you can use the floor function here.

Lets say for a give day, you have multiple timestamps.

then,

date(floor(timestamp#('<time_stamp>', 'FORMAT')))

or try date(floor(date#('<time_stamp>', 'FORMAT')))

here FORMAT is the format in which we get the data.

Let me know if it works.

Anonymous
Not applicable
Author

Both of them did not work 😞

Here is my code, i dont get any error with below, even i dont get any data in the field Data

LOAD

Week(starttime) AS [Week #],
WeekStart(starttime) as Week,
Year(starttime) AS Year,
Month(starttime) AS [Month #],
MonthStart(starttime) as Month,
Day(starttime) AS [Day],
Weekday(starttime) AS WeekDay,
//Date(starttime) as Date,
Date(monthstart(starttime), 'MMM-YYYY') AS MonthYear,
Week(starttime)&'-'&Year(starttime) AS WeekYear,
hour(starttime) as BuildHour,
BuildSizeMB,BuildID,
Action,Duration,FileCount,ProductLine,Duration_Min,
UserName,JobName,
//date(floor(starttime('starttime', 'MM/DD/YYYY'))) as Date,
date(floor(date#('starttime', 'MM/DD/YYYY')))as Date

;

Load
converttolocaltime(starttime,'Pacific Time (US & Canada)') as starttime,
BuildSizeMB,BuildID,
Action,Duration,FileCount,ProductLine,Duration_Min,
UserName,JobName

;

SQL select starttime,BuildID,
((bytecount)/1024/1024) as BuildSizeMB,(DURATION/60)AS Duration_Min,
Action,Duration,FileCount,ProductLine,SubmittedBy as 'UserName',JobName
FROM ASWTRANS.DBO.CRMBUILDMETRICS

Anonymous
Not applicable
Author

All looks correct excpet the "Date" field. It should be simply:
date(floor(starttime)) as Date
or, if you want to specify format explicitly:
date(floor(starttime), 'DD/MM/YY') as Date

Anonymous
Not applicable
Author

This works with the filter , but in current selection box, i see the time 12:00am , how do i avoid that...

Anonymous
Not applicable
Author

Go to Document Properties, tab "Number", and make sure that field Date is Date, not Timestamp nor Time.
You can also do this in list box properties, but it will effect only this list box. It's better on document level.

Anonymous
Not applicable
Author

Got it, Thank you ...