datetime

Date Culture Format Problem

I have been having problems working with dates. I need to have a DateTime instance that has the "dd-MM-yyyy" format. I'm NOT asking to have a string of my date instance in the "dd-MM-yyyy", that I know. I need to seed my date obj through the Entity framework, that calls a StoreProc that receives a param that it a Date... I can always ch...

Building up a monthly total from past 12 months

CurrentMonth = Month(CurrentDate) CurrentYear = Year(CurrentDate) SQL = "SELECT Spent, MONTH(Date) AS InvMonth, YEAR(Date) As InvYear FROM Invoices WHERE YEAR(Date) = '" & CurrentYear & "' AND MONTH(Date) = '" & CurrentMonth & "'" RecordSet.Open SQL, Connection, adOpenStatic, adLockOptimistic, adCmdText Do Until RecordSet.EO...

Setting SqlDateTime.Null in a constructor

How do I set a null value for an optional DateTime parameter in a constructor? I'm using the following constructor below and I want the optional parameter admissionDate to be a null DateTime. Setting it to Nothing actually gives it a value (something like #12:00:00 #). Public Sub New(ByVal obj1 as Object, Optional ByVal admissionDate ...

Convert Year/Month/Day to Day of Year in Python

I'm using the Python "datetime" module, i.e.: >>> import datetime >>> today = datetime.datetime.now() >>> print today 2009-03-06 13:24:58.857946 and I would like to compute the day of year that is sensitive of leap years. e.g. oday (March 6, 2009) is the 65th day of 2009. Here's web-based DateTime calculator. Anyway, I see a two opt...

How to create a unique constraint just on the date part of a datetime?

I'm writing a very simple blog engine for own use (since every blog engine I encountered is too complex). I want to be able to uniquely identify each post by its URL which is something like /2009/03/05/my-blog-post-slug. To accomplish it in the data tier, I want to create a compound unique constraint on (Date, Slug) where Date is only th...

Calculate the last DayOfWeek of a month

Given a DateTime and a DayOfWeek should return the date of the last DayOfWeek of that month. E.g. 1st-March-2009 and Sunday would return 29th-March-2009 ...

Memory leak when using time in NHibernate SQL query

I use NHibernate in my ASP.NET application to connect to an MS SQL Server 2005 database. In some cases I need to write my own SQL queries. However, I noticed that the SQL server thread leaks about 50 KB of memory every time I execute the following piece of code: NHibernate.ISession session = NHibernateSessionManager.Instance.GetSession(...

Date Range In PHP?

I have a DB created by a third party vendor that I'm now writing a new UI for. The DB stores event start times as unix timestamps (in GMT). What I need to do is query this for a one day range. So presumably I simply need to do a: SELECT * WHERE start > $last_night_at_midnight AND start < $tonight_at_midnight The problem I'm running i...

Date Time Conversion

I want to convert mm/dd/yyyy to dd/mm/yyyy. My application is asp.NET with VB. I tried following code DateTime.Parse(oldDate.ToString("dd\mm\yyyy")) But got the error: "The string was not recognized as a valid dateTime. There is an unknown word starting at index 2" Can any one give the appropriate code? ...

SQL Dates Query - how long has this condition been true

The question is how long have these customers been jerks on any given date. I'm working against Sybase For this simplified table structure of table history_data table: history_of_jerkiness processing_date name is_jerk --------------- ----- ------- 20090101 Matt true 20090101 Bob false 20090101 Al...

How to Properly Convert or Query Date Range for Rails / MySQL DateTime Column

I have a rails application where I store created_at as datetime (standard). I am building a form for searching and I find I have to use find_by_sql to do some complex subqueries. The form has a date range (no time) to search on for items created_at field. The problem I find is that if I pass in just the date string for range to query......

Algorithm to determine if a given date/time is between two date/time pairs

I have an array of dates in a one week range stored in an unusual way. The Dates are stored in this numeric format: 12150 From left to right: 1st digit represents day: 1 = sunday, 2 = monday, 3 = tuesday, ...., 7 = saturday next two digits represent hour in a 24 hour system: 00 = midnight, 23 = 11pm next two digits represent minutes...

Performing Date/Time Math In HQL?

I'm looking how to perform date/time math within an HQL query. Specifically, how do I add or subtract (x) amount of time from the result of the current_timestamp() function? Or do I have to drop into SQL for this and hope that whatever database is being run supports it? HQL query example: FROM RandomThing WHERE randomTime IS NOT NULL A...

Data Type of a field

Hey guys and gals, I have a field in a table that I will be storing different kinds of data in it, Like: X-Large, Medium, Small....or I might store: 22-March-2009, 1 Year, 2 Years, 3 Years...or 06Months, 12 Months, 1 Year, or I might store: "33-36", "37-40"...and that data is not fixed, i might need in the future to add new categories......

NHibernate won't persist DateTime SqlDateTime overflow

I am working on an ASP.NET MVC project with NHibernate as the backend and am having some trouble getting some dates to write back to my SQL Server database tables. These date fields are NOT nullable, so the many answers here about how to setup nullable datetimes have not helped. Basically when I try to save the entity which has a DateA...

datetime conversion c#

how would you convert this date into c# Datetime object? Mon Mar 16 14:21:27 +0000 2009 i tried parseexact with format = "ddd MMM dd hh:mm:ss zzzz yyyy" but it didn't work. what did i do wrong? ...

How many days until XXX date?

Given a certain date, whats the easiest way to determine how many days until that date (in PHP)? I am trying to build a count-down widget, Thanks! ...

Is there an easy way to Calculate and format time/date intervals in java?

I'm familiar with the the date and time classes in the JDK and their associated formatting methods. I may be blind, but I cannot find an equivalent set of classes for processing time intervals. For example, I would like to display the number of days for a given long value of milliseconds. I realize that the method to do these conversions...

Age from Date of Birth using JQuery

I need to calculate if someone is over 18 from their date of birth using JQuery. var curr = new Date(); curr.setFullYear(curr.getFullYear() - 18); var dob = Date.parse($(this).text()); if((curr-dob)<0) { $(this).text("Under 18"); } else { $(this).text(" Over 18"); } There must be some easier functions to use to compare dates...

How do I get the month number from the year and week number in c#?

As the title says, given the year and the week number, how do I get the month number? edit: if a week crosses two months, I want the month the first day of the week is in. edit(2): This is how I get the week number: CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay, DayOfWeek.Monday); I'm just...