datetime

Rounding up a free text date field, for use a 'Date To' criteria field

Hi, I've found that the Date.TryParse is pretty lenient on input - so skipping out the day or month will still return a value, though always floor rounded. E.g.: DateTime.TryParse("2010", out testDate) -> 01 Jan 2010 or DateTime.TryParse("may 2010", out testDate) -> 01 May 2010 I'd like to allow the user to input a date to be used...

Function to display a DateTime string or an empty string

I tried to create a view helper which takes a DateTime object and returns a string. If the DateTime object equals a new DateTime(0), the function returns an empty string. Otherwise return a formatted DateTime string. This works so far. public static string DateTimeOrEmpty(this HtmlHelper htmlHelper, DateTime dateTime) { return date...

Hibernate date mapping problem

I am using a SQL Server database and Hibernate. I have the following problem related to storing dates: I have the following code: String hql = "select user from User user where user.createDate = :date"; Query query = HibernateUtil.getSession().createQuery(hql); Date date2 = DateHelper.getEndOfDay(new Date());//this returns 2010-07-27 2...

php DateTime construct crash on wamp server

Hello, I have a problem with DateTime class. I'm using xampp server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 and there were no problems at all, but on the other server (wamp): Apache/2.2.11 (Win32) SVN/1.6.4 DAV/2 PHP/5.3.0 web ...

Hiding the time in a datetime model field in Django?

I'm using Thauber's lovely Django schedule app, but have run into a problem: I can't figure out how to exclude the time portion of the datetime field. My form class and lame exclusion attempt looks like this: class LaundryDeliveryForm(EventForm): start = forms.DateTimeField(widget=forms.SplitDateTimeWidget) end = forms.DateTim...

Converting a time string to UNIX timestamp

Hi How can I convert a time string like this: 30/7/2010 to a UNIX timestamp? I tried strtotime() but I get a empty string :( ...

How would you store a business's hours in the db/model of a Rails app?

I'm creating a Rails app that will store the opening and closing hours for a business. Originally, I thought of simply using a text data type and letting it be free-form: "Monday to Friday 9am to 5pm Saturday 11am to 4pm Closed Sundays" But, requirements have changed and I need to check the hours against the current date & time and di...

Preferred way to handle UTC/local time in Qt's QDateTime?

I have some code where I write a QDateTime to a file... someQDateTime.toUTC().toString(Qt::ISODate) and when I read it back using QDateTime::fromString(), I get the time interpreted as being in the system's time zone. I can manually append "Z" to the string when I write it out, or use setTimeSpec() after I read it, and then everything...

How to convert difference between dates into years using php.

Hi, I have dates in the format Start and end dates in the format(mm/yyyy). I want to display the difference of the dates in years, months. example: start date 09/2008 end date 07/2010 display should read 1 Year, 10 months. I appreciate any help. Thanks. ...

short regex datetime split

Hi, I'm trying to split the following: 2010-07-30 10:10:50 and I would like to ONLY end up with: 2010 07 30 normally with just the date, you regex with /-/ however now I would like something as simple as that but now i get 2010 07 30 10:10:50 how can i get that last part + space out? Thank you so much! ps, right now I need t...

How to remove DateTime.Parse dependency on System.Threading.Thread.CurrentThread.CurrentCulture

Consider the following code: class Program { static void Main(string[] args) { try { System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fo-FO"); var s = DateTime.MaxValue.ToString("yyyy-MM-ddTHH:mm:ssZ"); var d = DateTime.Parse(s, CultureInfo.InvariantCultu...

How can I convert a DateTime to the number of seconds since 1970?

I'm trying to convert a C# DateTime variable to Unix time, ie, the number of seconds since Jan 1st, 1970. It looks like a DateTime is actually implemented as the number of 'ticks' since Jan 1st, 0001. My current thought is to subtract Jan 1st, 1970 from my DateTime like this: TimeSpan span= DateTime.Now.Subtract(new DateTime(1970,1,1...

vbscript time zones and Daylight Savings

I'm looking for an easy way to get UTC times and date/time information in vbscript, even while specifying a time zone. I need to be able to get the current time in a time zone of my choice. I have seen postings on the web for functions that determine DST, but I'd rather not use something I'd have to update if DST or time zones switched...

C# DateTime time zone subtract issues

I have this line of code: double seconds = new DateTime(2006,7,6,12,1,0,DateTimeKind.Local).Subtract(new DateTime(1970,1,1,0,0,0,DateTimeKind.Local).TotalSeconds; This was not the right number I wanted, so I tried the following: double seconds = new DateTime(2006,7,6,12,1,0,DateTimeKind.Local).Subtract(new DateTime(1970,1,1,0,0,0,Dat...

C#: Iterate over each Day between StartDate and EndDate

I have a DateTime StartDate and EndDate. How can I, irrespective of times, iterate across each Day between those two? Example: StartDate is 7/20/2010 5:10:32 PM and EndDate is 7/29/2010 1:59:12 AM. I want to be able to iterate across 7/20, 7/21, 7/22 .. 7/29. Help? ...

Get integer date representation (epoc time or jan1st 0001 base) from string ( Fri 4/2/2004 9:55:54 AM --------> <long representation>)

I have the date in a string in the following format. Fri 4/2/2004 9:55:54 AM I would like to have a generic time utility in c++ which parses this and provides me the long/int representation which is either the epoc time base or Jan 1st 0001 time base. (Wish list) Also, it will be good if the util is fairly generic, in the sense that, ...

How to convert this TSQLcode to PostgreSQL /pgsql

Hi, ne need to convert the following tsql function code into a pgsql function and I have absolutely no idea how: BEGIN DECLARE @StartDate DATETIME DECLARE @ResultDate DATETIME SET @StartDate = CONVERT(DATETIME, 0) SET @ResultDate = CASE @Type WHEN 0 THEN DATEADD(mi, FLOOR(DATEDIFF(mi, @StartDate, @Date) / CAST(@Interva...

convert utc time and offset to DateTime

i have a datetime(in utc) saved in database and i also know the utc offset in the following format. -03:00:00 how to convert this to a DateTime ...

Javascript date functions

Hi, I'm having problems with the following JavaScript code. I coded in the comments what's happening: function fetchMaand() { var dteBegin, dteEnd, clsDate, monthsAhead; monthsAhead = $('#dteMaand').val(); // dteMaand's value = -3 for example clsDate = new Date(); // Current time clsDate.setMonth(clsDate.getMonth() + mo...

SQL Server DateTime Query Issue

I am using SqlServer Compact 3.5 (2008) and am trying to return rows that have a datetime field that is today or previous. This is the code I am trying, but it is throwing an exception. (in the Where clause) I'm new to SQL so I'm having trouble with this one. Any ideas? If you need more data, let me know. string selectStatement = "S...