at the start of edit script while defineing varibles
you can change the order of
SET TimeFormat='h:mm:ss TT';
SET TimestampFormat='M/D/YYYY h:mm:ss[.fff] TT';
instead of SETDayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';
and save application
hope this helps
Atlast I got fedup with QV's inbuild date functions and wrote a VBScript to get the previous year's week date
ctYear = Datepart("yyyy",dDate)
ctDayofYear = Datepart("y",dDate)
cyFirstDay = Datepart("w",datevalue("1/1/" & ctYear))
pyFirstDay = Datepart("w",datevalue("1/1/" & ctYear - 1))
GetPYWeekDate = dateadd("d", - (pyFirstDay - cyFirstDay) + ctDayofYear - 1, datevalue("1/1/" & ctYear - 1))
If anyone needs this, use it
Thanks for your input. It is returning 1 day more than the QV's normal weekday
Today() : 5/8/2012 (Tuesday)
WeekDay: Num(WeekDay(Today()),'#') : 1
MyWeekDay: Num(Dual(Subfield('$(DayNames)',';',WeekDay(Today())+1),Mod(Today()-1,7)),'#') : 2
If its Tuesday, it should return either 2(Weekday) / 3(MyWeekDay), but it is returning 1 / 2. Does this mean that Weekday starts with zero?
My function will return the foll
GetPYWeekDate(Today()) = 5/3/2011
How to achieve the above using only QV script instead of VBS?
We can easily subtract a day to get the week's start day as Sunday even without using these many conversions, but Week function will not return the correct Week # for the StartDate of the Week
Is there something like AddDays similar to AddMonths & AddYears? I think that may resolve this issue. I don't want to use "+ <days>" to add days
My basic requirement is I want to set the start of the week to be Sunday instead of Monday permanently, and not temporary (still I haven't got the answer).
If that is the case, then only the current year's week number and previous year's week number are tallying, else it is not.
1/1/2012 - Weekstart should be 1 instead of 7 (1st week) - in QV, this is the last week's last day of previous year
and 1/1/2011 - Weekstart should be 7 instead of 6 (prev year's last week) - So 1st week of year 2011 starts on 2nd Jan and not on 3rd
If the above condition satisfies, then only we can get the answer for proper Week over Year value
Both the built-in WeekDay and my function start at 0 and go to 6. With this definition WeekDay for today should be 1 (second day of week) and my function should be 2 (third day of week). You can check this yourself by formatting a listbox with WeekDay as a number (Properties - Number).
But for my function you can easily change this if you want an other value: The Dual function takes two parameters - the second defines the number. So, just change Mod(Date-1,7) to Mod(Date-1,7)+1. It will still work using Sunday as the first day of the week.
The function WeekStart does not change, so it will still return Monday as the first day of the week. (ISO 8601; http://en.wikipedia.org/wiki/ISO_week_date)
+ Dual(DayNumberOfYear(vCYStartDate)) - 1
Is this the way to achieve previous year's weekday using your MyWeekDay?
I am not sure if I understand what you are trying to do... If it is just a matter of getting the weekday of previous years day, then you can use "WeekDay(AddMonths(Date, -12))" or with the alternative Weekday function around the AddMonths function instead.
The Dual function should normally be the outermost function:
<Text that you want to display>,
<Number that is a unique identifier for the day/date>
Btw, there is no function AddDays because you do not need one. You should indeed just use "Date( Date+<days>)".
If we use AddMonths or AddYears, it will give exactly the same date rather than the same day of previous year
For example, if today is Tuesday, 8th May 2012, I don't want 8th May 2011 which is Sunday
8th May 2012 is Week 19 and Day 3 (Sunday being the first day)
8th May 2011 is Week 20 and Day 1
So my result should be Day 3 of 19th week of 2011 (May 3rd 2011) and not the same date of 2011 (May 8th 2011)
If you use the attached script, then you can calculate week number and week day so that Jan 1st always belongs to week 1 and Sunday always is the first day of the week. Then you can compare year-to-year numbers using WeekNumber and WeekDay: (Note that the difference from previous year is calculated also)
Should you want to calculate the date of the previous year's corresponding date in the script, you can do this also. See attachment.
Hello @ Henric Cronström,
This piece of code is indeed useful, but I want to know how to tweak this to suit my case.
Here the US Week 1 is Jan 1 - Jan 4 2014 - where we want to have the Dec 29th to Jan 4 2014 as Week 53 of 2013 instead.
The definition of our week is that a Week Starts Sunday and should have 7 days, in the above calendar has a week which is less than 7 days - so in case when I have to compare Week 1 of Jan 2014 to Week 2 to Jan 2014 I end up comparing 4 days to 7 days.
Any thoughts ?