I would like to sort my model's data on a week number for example when user logins user will see current week number and associated data and user should be able to select previous week number and get all past data as well also week starts on Sunday and ends on Saturday (considering 1 week)
Select Week :[2021 - 30 ] <- week number
You can filter it such way:
from datetime import datetime, timedelta
itemsList = Model_Name.objects.filter(user=request.user, created_date__gte=datetime.now()-timedelta(days=7))
I have got similar problem in my task and I solved it in simple steps:
#django #django-models #django-views #problem-solving
def get_weeks(request):
week = now().isocalendar()
if Event.objects.filter(start_date__week=week.week).exists():
instances=Event.objects.filter(start_date__week=week.week)
I have a field with a date in yyyy-MM-dd format, I want to extract the day only, for example, if the date is 2014-01-25, I want to have "25" in a new field. I used step "Calculator" is calculation "day of month of date A" but I get 1970-01-01 01:00:00 for all records.
Could someone tell me what might be the reason?
Before you actually have the Calculator step, have a Select Values step and make sure the date field is Date by explicitly giving the Date data type and specify the format it is currently in.
So I am looking to display payments from individual donors over a time period between their first donation, and today's date.
To fill gaps in a visual representation of donations over time, I use a calendar table and select ‘show items with missing data.’
My issue is that if a donor first donated in 2005 the fact that the calendar table starts in 1980 means the graph shows an X axis date range starting that year. So it's showing a lot of time we know has no data.
How can I default the date range to start at the date of the first donation of the user ID passed to the report?
Tables: Calendar, Donations
One way to achieve this is to create a measure that checks to see if there are donations within the current filter context. For your chart this will be for the date and donor category selections, though this would work in any other filter context that relates to donations.
It will look similar to this:
Has Donations =
if(calculate(isempty(relatedtable(DonationsTable
)
)
)
,0
,1
)
You can then add this filter to the Filters on this visual section of the Filter Pane and check for where the value is 1, though make sure your date axis is set to continuous. This will return all dates between the oldest and newest donation.
If I have 2 tables containg datetime field.
One tables' datetime field contains value like 01-01-2017 00:00:00 (only one value for one date and same time as 00:00:00)
Second tables' datetime field contains value like 01-01-2017 11:30:00 (there can be multiple values for one date and different time)
Now, the problem is if create 2 different charts from these 2 tables with datetime field on x axis. and select one date from first tables' chart: 2nd tables' chart is not getting updated by only selected datetime field on x axis. it is showing all datetime field and just highlighting selected datetime data.
I want to show only selected datetime data in 2nd chart.
Please help!
I have created table with Employee, and I have columns such as Name, WorkingDays (datatype is date). I want to write a query that will output something like
"select Name from Employee where WorkingDay = 'monday', 'wednesday' and 'friday' "
i.e..I want to make a roaster for the workers. I am using sqlite and QT. thanks in advance.
As per Date And Time Functions documentation, you can use strftime function in this way:
SELECT Name FROM Employee WHERE strftime('%w',WorkingDay) IN ('1','3','5');
Where ('1','3','5') are ('Monday', 'Wednesday', 'Friday') respectively.
An off-topic note:
WorkingDays (datatype is date)
There's no such thing in SQLite. From Datatypes In SQLite Version 3 documentation:
1.2 Date and Time Datatype
SQLite does not have a storage class set aside for storing dates
and/or times. Instead, the built-in Date And Time Functions of SQLite
are capable of storing dates and times as TEXT, REAL, or INTEGER
values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic
Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these
formats and freely convert between formats using the built-in date and
time functions.
Update
so that for example if today is friday, then automatically this name
appears on the names working today. Is it possible?
Yes it is. Just need to use strftime() function properly. I'll give you a little example:
CREATE TABLE Employee(
id INTEGER PRIMARY KEY,
name VARCHAR
);
CREATE TABLE WorkingDays(
id INTEGER PRIMARY KEY,
employee INTEGER,
dayNumber INTEGER,
FOREIGN KEY(employee) REFERENCES Employee(id),
UNIQUE(employee,dayNumer)
);
INSERT INTO Employee(name) VALUES('Max');
INSERT INTO Employee(name) VALUES('dic19');
INSERT INTO WorkingDays(employee,dayNumber) VALUES(1,1); --Max, Monday
INSERT INTO WorkingDays(employee,dayNumber) VALUES(1,2); --Max, Tuesday
INSERT INTO WorkingDays(employee,dayNumber) VALUES(1,3); --Max, Wednesday
INSERT INTO WorkingDays(employee,dayNumber) VALUES(2,4); --dic19, Thursday
INSERT INTO WorkingDays(employee,dayNumber) VALUES(2,5); --dic19, Friday
INSERT INTO WorkingDays(employee,dayNumber) VALUES(2,6); --dic19, Saturday
SELECT e.name
FROM WorkingDays w
LEFT JOIN Employee e ON w.employee = e.id
WHERE cast(w.dayNumber as text) = strftime('%w','now');
-- Right now it should return 'dic19' because Today is Friday/Saturday (depends on time zone)
SELECT e.name
FROM WorkingDays w
LEFT JOIN Employee e ON w.employee = e.id
WHERE cast(w.dayNumber as text) = strftime('%w','2013-11-11');
-- Should return 'Max' because '2013-11-11' was Monday