weekday

Equivalent of WeekDay Function of VB6 in C#

十年热恋 提交于 2019-11-29 07:12:22
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? 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. You mean the DateTime.DayOfWeek property? DayOfWeek dow = DateTime.Now.DayOfWeek; Yes, Each DateTime value has a built in property called DayOfWeek that returns a enumeration of the same name... DayOfWeek

Get weekdays in English in R

a 夏天 提交于 2019-11-28 17:37:30
I am using R outside the US and I got everything working in English, but the result of weekdays() is still in Spanish: Day <- seq(as.Date("2013-06-01"), by=1, len=30) weekdays(Day) [1] "sábado" "domingo" "lunes" "martes" "miércoles" (...) Any ideas on how to get the weekdays in English? Printing of Date and POSIX*t objects seems to be controlled by the LC_TIME locale category. On Windows, you change it like this: ## First in Spanish Sys.setlocale("LC_TIME","Spanish Modern Sort") # [1] "Spanish_Spain.1252" weekdays(Sys.Date()+0:6) # [1] "lunes" "martes" "miércoles" "jueves" "viernes" "sábado" #

Swift - Weekday by current location by currentCalendar()

做~自己de王妃 提交于 2019-11-28 13:30:34
Today is Wednesday and I have this code let calendar:NSCalendar = NSCalendar.currentCalendar() let dateComps:NSDateComponents = calendar.components(.CalendarUnitWeekday , fromDate: NSDate()) let dayOfWeek:Int = dateComps.weekday dayOfWeek is 4, but today is 3rd day of the week in Bulgaria. Is in USA today is 4th day of the week? And how to determine when the week starts in different countries and regions ? On my iPhone locale and calendar are set to Bulgarian calendar and locale and it knows that the week starts on Monday on my iMac also, but when I execute code it writes me 4... For the

Get next date from weekday in JavaScript

a 夏天 提交于 2019-11-28 11:59:16
How can one return the next date of a given weekday (it could be either a number 0-6 or names Sunday-Saturday). Example, if today, on Friday 16-Oct-2009 I passed in: Friday , it would return today's date 16-Oct-2009 Saturday returns 17-Oct-2009 Thursday returns 22-Oct-2009 Just adding 7 doesn't solve the problem. The below function will give you the next day of the week. function nextDay(x){ var now = new Date(); now.setDate(now.getDate() + (x+(7-now.getDay())) % 7); return now; } Here's a slightly modified version to Tim's answer to address the specific question-- pass in a date d, and, and a

Objective C - How can i get the weekday from NSDate?

房东的猫 提交于 2019-11-28 11:02:07
I need to be able to get the weekday from nsdate, i have the following code and it always return 1. I tried to change the month, i tried everything from 1 to 12 but the result of the week day is always 1. NSDate *date2 = [[NSDate alloc] initWithString:[NSString stringWithFormat:@"%d-%d-%d", 2010, 6, 1]]; unsigned units2 = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit; NSCalendar *calendar2 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components2 = [calendar2 components:units2 fromDate:date2]; int startWeekDay =

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

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,

Get number of weekdays in a given month

狂风中的少年 提交于 2019-11-27 15:41:44
I want to calculate the number of weekdays days in a give month and year. Weekdays means monday to friday. How do i do it ? Some basic code: $month = 12; $weekdays = array(); $d = 1; do { $mk = mktime(0, 0, 0, $month, $d, date("Y")); @$weekdays[date("w", $mk)]++; $d++; } while (date("m", $mk) == $month); print_r($weekdays); Remove the @ if your PHP error warning doesn't show notices. You don't need to count every day in the month. You already know the first 28 days contain 20 weekdays no matter what. All you have to do is determine the last few days. Change the start value to 29. Then add 20

Swift - Weekday by current location by currentCalendar()

六眼飞鱼酱① 提交于 2019-11-27 07:41:33
问题 Today is Wednesday and I have this code let calendar:NSCalendar = NSCalendar.currentCalendar() let dateComps:NSDateComponents = calendar.components(.CalendarUnitWeekday , fromDate: NSDate()) let dayOfWeek:Int = dateComps.weekday dayOfWeek is 4, but today is 3rd day of the week in Bulgaria. Is in USA today is 4th day of the week? And how to determine when the week starts in different countries and regions ? On my iPhone locale and calendar are set to Bulgarian calendar and locale and it knows