dates

What is wrong with my Oracle 10gr2 check constraint? Trying to enforce a date range

I want to enforce CHECK constraint on a date range such that all dates in column BIRTH_DATE are less than tomorrow and greater than or equal to 100 years ago. I tried this expression in a CHECK constraint: BIRTH_DATE >= (sysdate - numtoyminterval(100, 'YEAR')) AND BIRTH_DATE < sysdate + 1 But I received the error "ORA-02436: date or ...

Best way to turn an integer into a month name in c#?

Is there a best way to turn an integer into its month name in .net? Obviously I can spin up a datetime to string it and parse the month name out of there. That just seems like a gigantic waste of time. ...

Calculate last day of month in javascript

if you provide 0 as the dayValue in Date.setFullYear you get the last day of the previous month: d = new Date(); d.setFullYear(2008, 11, 0); // Sun Nov 30 2008 There is reference to this behaviour at mozilla. Is this a reliable cross-browser feature or should I look at alternative methods? ...

How do I calculate the previous business day in ksh shell script ?

What is the most elegant way to calculate the previous business day in shell ksh script ? What I got until now is : #!/bin/ksh set -x DAY_DIFF=1 case `date '+%a'` in "Sun") DAY_DIFF=2 ;; "Mon") DAY_DIFF=3 ;; esac PREV_DT=`perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-${DAY_DIFF}*24*60*60...

How to sanity check a date in java

I find it curious that the most obvious way to create Date objects in Java has been deprecated and appears to have been "substituted" with not so obvious to use lenient calendar. So... How do you check that a date given as a combination of day, month and year is a valid date? For instance a date 2008-02-31 (as in yyyy-mm-dd) would be in...

PHP mangles my dates

$doba = explode("/", $dob); $date = date("Y-m-d", mktime(0,0,0, $doba[0], $doba[1], $doba[2])); The above code turns any date i pass through into 1999-11-30 and i know it was working yesterday. Date is correct when I echo $doba. Anyone have any ideas? Cheers ...

Count number of Mondays in a given date range

Given a date range, I need to know how many Mondays (or Tuesdays, Wednesdays, etc) are in that range. I am currently working in C#. ...

Count work days between two dates in T-SQL

How can I calculate the number of work days between two dates in SQL Server? Monday to Friday and it must be T-SQL. ...

NSDateFormatter won't parse dates using locale settings?

I'm trying to parse dates using the user's date preferences [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateStyle:NSDateFormatterShortStyle]; NSDate *date = [ dateFormatter dateFromString:@"7/4/2008" ]; NSLog(@...

VB date conversion

Is there an easy way to convert a string that contains this: Date: Wed, 5 Nov 2008 13:12:12 -0500 (EST) into a string that contains this: 20081105_131212 UPDATE: I ended up using date.tryparse which is similar to tryParseExact except you don't have to specify the format string. I did have to eliminate the () and the EST for this t...

Seen this binary date format?

3/10/2008 = 1822556159 2/10/2008 = 1822523391 1/10/2008 = 1822490623 30/09/2008 = 1822392319 29/09/2008 = 1822359551 This is all the information that I know at the current time. Dates increment by 32768 except when changing month when the increment is 32768 x 2 (65536). Has anyone seen this binary date format and how can I extrac...

Adding Days to a Date but Excluding Weekends

Given a date how can I add a number of days to it, but exclude weekends. For example, given 11/12/2008 (Wednesday) and adding five will result in 11/19/2008 (Wednesday) rather than 11/17/2008 (Monday). I can think of a simple solution like looping through each day to add and checking to see if it is a weekend, but I'd like to see if the...

How do I determine if a given date is Nth weekday of the month?

Sorry if the title is awkward, but I can't think of a better summary. Here is what I am trying to do: Given a date, a day of a week and an integer n, is the date the nth day of the month? For example: input of 1/1/2009,Monday,2 would be false because 1/1/2009 is not the second Monday input of 11/13/2008,Thursday,2 would return true ...

How can I parse relative dates with Perl?

I'd love to know if there is a module to parse "human formatted" dates in Perl. I mean things like "tomorrow", "Tuesday", "next week", "1 hour ago". My research with CPAN suggest that there is no such module, so how would you go about creating one? NLP is way over the top for this. ...

Simple Oracle SQL date syntax question

I am trying to convert a working MS Access query to run on an Oracle database being accessed via VB Script (.asp). This is the last section of the WHERE clause: sql = sql & "WHERE (UAT.HB.MB_MODE = 'A' AND UAT.HB.PRINT_DATE >= '" & SD & "' AND UAT.HB.PRINT_DATE <= '" & ED &"' )" The variable "SD" (i.e. "start date") is a text str...

Calculate the last day of the quarter

What's the most efficient way to calculate the last day of the prior quarter? Example: given the date 11/19/2008, I want to return 9/30/2008. Platform is SQL Server ...

PHP/MySQL: Retrieving the last *full* weeks entries

Hi, I'm currently using the following SQL for retrieving the last seven days worth of entries from a table: purchased >= date_sub(now() ,interval 7 day) However, I need to change this so it retrieves the last full weeks worth of entries (midnight Saturday to midnight Saturday). So basically, throughout the week the results never chan...

Localization: Do all locales put the weekday before the date?

Here's a simple (hopefully) L10N question: Do all locales want this format: Sunday, Nov 23, 2008 with the weekday before the date, or do some locales want it after the date like this? Nov 23, 2008, Sunday ...

Calculate time period using C

How would I calculate a time period between 2 dates using C (any library, etc.). For example the program would take two (local) dates and would spit out the period duration between them. For example startDate = oct-9-1976 and endDate = oct-9-2008 would show a duration of 32 years OR startDate = oct-9-1976 and endDate = dec-9-2008 would s...

Calculate business days

Hi, I need a method for adding "business days" in PHP. For example, Friday 12/5 + 3 business days = Wednesday 12/10. At a minimum I need the code to understand weekends, but ideally it should account for US federal holidays as well. I'm sure I could come up with a solution by brute force if necessary, but I'm hoping there's a more eleg...