dayofweek

Order by day_of_week in MySQL

情到浓时终转凉″ 提交于 2019-11-28 20:46:55
How can I order the mysql result by varchar column that contains day of week name? Note that MONDAY should goes first, not SUNDAY. Glen Solsberry Either redesign the column as suggested by Williham Totland, or do some string parsing to get a date representation. If the column only contains the day of week, then you could do this: ORDER BY FIELD(<fieldname>, 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY'); Joseph Manganelli Why not this? ORDER BY ( CASE DAYOFWEEK(dateField) WHEN 1 THEN 7 ELSE DAYOFWEEK(dateField) END ) I believe this orders Monday to Sunday... I'm

In Java, how to get strings of days of week (Sun, Mon, …, Sat) with system's default Locale (language)

大憨熊 提交于 2019-11-28 10:43:00
The simplest way: String[] namesOfDays = new String[7] { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; This method does not use Locale. Therefore, if the system's language is not English, this method does not work properly. Using Joda time, we can do like this: String[] namesOfDays = new String[7]; LocalDate now = new LocalDate(); for (int i=0; i<7; i++) { /* DateTimeConstants.MONDAY = 1, TUESDAY = 2, ..., SUNDAY = 7 */ namesOfDays[i] = now.withDayOfWeek((DateTimeConstants.SUNDAY + i - 1) % 7 + 1) .dayOfWeek().getAsShortText(); } However, this method uses today's date and calendar

How to find nearest day of week in php?

你离开我真会死。 提交于 2019-11-28 10:08:43
How to find a speciefic nearest day of the week in PHP if initially I have a date string like: 07.05.2010 ? For example, I want to find the nearest Sunday (or any day of the week). How can I implement this? Thanks This should do: echo date('d.m.Y', strtotime('next Sunday', strtotime('07.05.2010'))); Just in case you wanted the nearest day rather than the next one, here is a way to do that. $target = "Sunday"; $date = "07.05.2010"; // Old-school DateTime::createFromFormat list($dom, $mon, $year) = sscanf($date, "%02d.%02d.%04d"); $date = new DateTime("$year/$mon/$dom -4 days"); // Skip ahead to

can we group by day of the week using hibernate?

a 夏天 提交于 2019-11-28 06:08:40
问题 I want the query results to be grouped by day of the week .. like into 7 groups Monday, Tuesday, Wednesday... etc one for each the column in the table is a timestamp field like 12-Mar-2011 ..... so I don't care which dates exist in the table I just need to get 7 groupings and if there is a count column which doesnt exist for like thursday it should return 0 and for wednesday the count should the total counts for all wednesday and like wise for each day of the week. How do I mplement this

Averaging daily data into weekly data

人盡茶涼 提交于 2019-11-28 04:35:47
问题 I am wondering if there is a way to average daily data into weekly data. The dataframe that I call CADaily looks like this: > CADaily[1:10, ] Climate_Division Date Rain 885 1 1948-07-01 0.8750000 892 1 1948-07-02 2.9166667 894 1 1948-07-03 0.7916667 895 1 1948-07-04 0.4305556 898 1 1948-07-05 0.8262061 901 1 1948-07-06 0.5972222 904 1 1948-07-17 0.04166667 905 1 1948-07-18 0.08333333 907 1 1948-07-20 0.04166667 909 1 1948-07-22 0.12500000 910 1 1948-07-21 NA My objective is similar to the

How to get day from specified date in android

不羁的心 提交于 2019-11-28 02:02:48
Suppose my date is 02-01-2013 and it is stored in a variable like: String strDate = "02-01-2013"; then how should I get the day of this date (i.e TUESDAY)? Use Calendar class from java api. Calendar calendar = new GregorianCalendar(2008, 01, 01); // Note that Month value is 0-based. e.g., 0 for January. int reslut = calendar.get(Calendar.DAY_OF_WEEK); switch (result) { case Calendar.MONDAY: System.out.println("It's Monday !"); break; } You could also use SimpleDateFormater and Date for parsing dates Date date = new Date(); SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd"); try

Equivalent of WeekDay Function of VB6 in C#

自闭症网瘾萝莉.ら 提交于 2019-11-28 00:57:39
问题 In VB6 code, I have the following: dim I as Long I = Weekday(Now, vbFriday) I want the equivalent in C#. Can any one help? 回答1: public static int Weekday(DateTime dt, DayOfWeek startOfWeek) { return (dt.DayOfWeek - startOfWeek + 7) % 7; } This can be called using: DateTime dt = DateTime.Now; Console.WriteLine(Weekday(dt, DayOfWeek.Friday)); The above outputs: 4 as Tuesday is 4 days after Friday. 回答2: You mean the DateTime.DayOfWeek property? DayOfWeek dow = DateTime.Now.DayOfWeek; 回答3: Yes,

How to set monday as first day of week in SQL Server

我只是一个虾纸丫 提交于 2019-11-27 23:39:11
I am running SQL Server 2008 on a machine with regional settings that have Monday as the first day of the week. If I create a computed column in a table to compute the day of week for a date field then I get 2 for a Monday date instead of 1. Is there some property for the table or database or server that I need to set ? The first day of the week is based on your language settings of the server. The default setting for us_english is 7 (Sunday) You can find the current first day of the week by using SELECT @@DATEFIRST However, you can use DATEFIRST for this. Just put it at the top of your query

How to get the integer value of day of week

故事扮演 提交于 2019-11-27 18:54:29
How do I get the day of a week in integer format? I know ToString will return only a string. DateTime ClockInfoFromSystem = DateTime.Now; int day1; string day2; day1= ClockInfoFromSystem.DayOfWeek.ToString(); /// it is not working day2= ClockInfoFromSystem.DayOfWeek.ToString(); /// it gives me string Use day1 = (int)ClockInfoFromSystem.DayOfWeek; int day = (int)DateTime.Now.DayOfWeek; First day of the week: Sunday (with a value of zero) If you want to set first day of the week to Monday with integer value 1 and Sunday with integer value 7 int day = ((int)DateTime.Now.DayOfWeek == 0) ? 7 : (int

Get last Friday's Date unless today is Friday using T-SQL

ぐ巨炮叔叔 提交于 2019-11-27 17:32:46
问题 I'm trying to get the correct SQL code to obtain last Friday's date. A few days ago, I thought I had my code correct. But just noticed that it's getting last week's Friday date, not the last Friday. The day I'm writing this question is Saturday, 8/11/2012 @ 12:23am. In SQL Server, this code is returning Friday, 8/3/2012. However, I want this to return Friday, 8/10/2012 instead. How can I fix this code? Since we're getting to specifics here, if the current day is Friday, then I want to return