I have the following situation:
QDate fixDate = QDate::fromString(QString("270912"), "ddMMyy");
the year returned is 1912. I do not understand why and how get the correct year.
Thanks in advance
Two-digit year is always interpretating as 19xx.
So You can pass YYYY or just add 100 to years.
As described in the docs:
For any field that is not represented in the format the following defaults are used:
Year 1900
Month 1
Day 1
// For example:
QDate::fromString("1.30", "M.d"); // January 30 1900
QDate::fromString("20000110", "yyyyMMdd"); // January 10, 2000
(Excuse the formatting, it's in a table in the docs). So you are going to have to pass the full year into the method until Qt decide 2012 is far enough into the century to change the default...
Could you use ddMMyyyy instead of ddMMyy? Or you need date in this format?
Look here for more information about fromString method
Related
I tried to get the start date of a specific week in Moment.js from the week number and year by doing moment().year(...).isoWeek(...).startOf('isoWeek')
But It seems that this function is not always returning the correct date.
For example when I live in England and a week always starts on a monday.
We should get 31 Dec 2018 when we ask for the first day of week 1, 2019.
This wasn't the case on 31 Dec 2018 as the result I received was 30 Dec 2019 as the begin date of week 1, 2019. See example
I think I found the solution I was looking for
moment()
.isoWeekYear(year)
.isoWeek(week)
.startOf('week')
Please note that, as i18n section of the docs states:
By default, Moment.js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.js for later use.
So if you want to use en-gb locale you have explicitly load it (in the browser, you can use en-gb.js file or moment-with-locales.js and then set locale using moment.locale('en-gb')).
You don't have to use year() setter, because it sets the year to 2019 and moment().year(2019).isoWeek(1) gives you the first isoweek of the 2020. You can create a moment object for a given year using moment({y: year}) instead.
You have to use week() instead of isoWeek if you want locale dependent results:
Because different locales define week of year numbering differently, Moment.js added moment#week to get/set the localized week of the year.
The week of the year varies depending on which day is the first day of the week (Sunday, Monday, etc), and which week is the first week of the year.
Here a full code sample:
// Set locale to British English
moment.locale('en-gb');
var year = 2019;
var firstMonday = moment({y: year}) // get first day of the given year
.week(1) // get the first week according locale
.startOf('week'); // get the first day of the week according locale
// Show result
console.log(firstMonday.format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment-with-locales.min.js"></script>
You can use format() to display the value of a moment object.
I there a way I can get a date through week and weekday?
so far I have for example:
var week_number= 42, weekday = 4;
I have read most of the docs and searches in google and found nothing regarding this.
NOTE: To keep my code standard I would like to use momentjs
UPDATE: I am able to get the date through the week but what about the real date through weekday number?
var week_date = moment().week(week_number),
weekday_date = ????
You probably want to do this:
moment().week(42).weekday(4).startOf('day')
Though you should consider whether you should use week or isoWeek, and you should also consider whether to use weekday, day, or isoWeekday.
All of these functions, and the differences between them are in the moment.js documentation.
I generate a vcalendar file with DTSTART and DTEND with week numbers and day of week just like RFC5545 and ISO.8601.2004 1 says. Like so:
DTSTART:2015W437T200000Z
DTEND:2015W437T210000Z
or
DTSTART:2015-W43-7T200000Z
DTEND:2015-W43-7T210000Z
Which read year 2015 week 43 day 7 (Sunday) 8.00pm to 9.00pm.
But neither google-calendar nor an online validator I've come across says that it's correct. Anyone got an idea whats going on?
As the Calendar API docs state, the format does not take weeks; instead, it uses RFC3339 and should read
DTSTART:2015-10-25T20:00:00Z
DTEND:2015-10-25T21:00:00Z
I have a Report that I send a parameter to as 'WeekStart'. This is based on a selection a user makes on a datepicker.
I'm using the following to extract the week of the year:
=DatePart("ww", Parameters!WeekStart.Value)
The problem I'm having is that when I pick the day 03/01/2012 (dd/MM/yyyy format), the week of the year is returned as 9, which would technically be true had the date been 03/01/2012 with a dateformat of MM/dd/yyyy.
I've tried using CDate, FormatDateString etc but nothing seems to be working. I either get #Error or it returns as the 9th week of the year.
Any suggestions?
What you can do is this:
use YourDatabase
go
set dateformat dmy
go
That will set the date format for your database, and that should get your DATEPART function working as expected.
SET DATEFORMAT (MSDN)
Is it possible to write a SQL query that sorts data set by day of week starting from a specific day?
For example, if today is Thursday, the results are sorted from THU-FRI-SAT-...-MON-TUE-WED.
If today is Tuesday, the results would be sorted from TUE-WED-THU-...-SAT-SUN-MON.
Days are stored as integers.
Assuming you have the day of the week stored into field WD where value 1 means MON, 2 means TUE etc and SW is the "start of the week" index (again 1:MON, 2:TUE,...) then something like
CASE WHEN WD < SW THEN WD + 7 ELSE WD END
should give you a value to order by. I don't use sqlite so I'm not sure can you put it right into the ORDER BY or do you have to use it as a field and then order by that field.
in mysql: ORDER BY DATE_FORMAT(date,%w)
see: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
Microsoft databases suport this (not shure)
... ORDER by DATENAME ( dw , table.datefield )
Check out DATEPART:
http://www.tizag.com/sqlTutorial/sqldatepart.php