# Thread: Get dates of current week

1. Member
Join Date
Nov 2008
Posts
2
Rep Power
0

## Get dates of current week

Hello everyone,

I want to know the dates of the current week, starting from mon to sun.
the current date is no problem and the current week isn't a problem either.
I set up a test where i get a couple of info from the current time:
Calendar cal = Calendar.getInstance();
Java Code:
```	int day = cal.get(Calendar.DATE);
int week = cal.get(Calendar.WEEK_OF_YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int dow = cal.get(Calendar.DAY_OF_WEEK);
int dom = cal.get(Calendar.DAY_OF_MONTH);
int doy = cal.get(Calendar.DAY_OF_YEAR);

System.out.println("Current Date: " + cal.getTime());
System.out.println("Day: " + day);
System.out.println("Month: " + month);
System.out.println("Year: " + year);
System.out.println("Weeknumber: " + week);
System.out.println("Day of Week: " + dow);
System.out.println("Day of Month: " + dom);
System.out.println("Day of Year: " + doy);```
an example of the result:
Current Date: Tue Nov 18 11:10:26 CET 2008
Day: 18
Month: 11
Year: 2008
Weeknumber: 47
Day of Week: 3
Day of Month: 18
Day of Year: 323

So how could i get the start and enddate of this week? (considering Mon is day 1 instead of 2 and sunday is 7 instead of 1)?

and how can i convert those dates to epochs?

2. Since you know the current day in terms of number and mon,tues, etc and cal.getTime knows the day in terms of day of the week check for a method that could return that.

You need to know if its Monday or Tuesday and the numeric date together in order to subtract to get the first day and add to get the last day. Since monday is 1 instead of sunday your going to need something like
Java Code:
```if(day = 1 //sunday)
startWeek = 2; //monday
day = 2;
if (startWeek = 2)
day = monday```
It's a tad confusing since day is both a numeric and string representation. Your basically just working with the current day values and overriding everything to work for the next day. When you get to sunday though your going to need to be clever about making sure that your week can goto 8 so you can have sunday set as 7 and then just reset the counter.

As for epochs I have no idea what that even is so I wouldn't know.

3. Member
Join Date
Nov 2008
Posts
2
Rep Power
0
Thanks,
but i think i solved it by calculating the difference between the current day of the week and monday and sunday.
All i have to do then is check if that works when the start or endday of the week isn't in the same month.

As for epoch....
Thats the date calculate from the number of seconds passed scince 1-1-1970.
It's used in a lot of databases because you don't have problems with timezones.
google epoch converter for some examples. (really handy if you want to calculate something between dates)
and in sql you can use select abstime(epoch::int); to select the epoch as a date.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•