datetime

MySQL compare DATE string with string from DATETIME field.

Hello. I have a question: Is it possible to select form MySQL database by comparing one DATE string "2010-04-29" against strings that are stored as DATETIME (2010-04-29 10:00) ? I have one date picker that filters data and I would like to query the table by the DATETIME field like this: SELECT * FROM `calendar` WHERE startTime = '2010-...

Time diff calculations where date and time are in seperate columns

I've got a query where I'm trying to get the hours in duration (eg 6.5 hours) between two different times. In my database, time and date are held in different fields so I can efficiently query on just a startDate, or endDate as I never query specifically on time. My query looks like this SELECT COUNT(*), IFNULL(SUM(TIMEDIFF(endTime,...

Convert UNIX timestamp to .NET DateTime ticks in unmanaged code (without using .NET)

I need to "construct" .NET DateTime values in Python/C++. How can I compute the number of ticks stored by DateTime starting from a UNIX timestamp? A solution involving Win32 API calls it's ok (I believe FILETIME functions could help). ...

How should I check that a given argument is a datetime.date object?

I'm currently using an assert statement with isinstance. Because datetime is a subclass of date, I also need to check that it isn't an instance of datetime. Surely there's a better way? from datetime import date, datetime def some_func(arg): assert isinstance(arg, date) and not isinstance(arg, datetime),\ 'arg must be a dat...

Recursive SQL, have the last three values increased?

Hi, I have a table that looks like this: ---------------------- | DateTime | Value | ---------------------- | 2010-01-01 | 26 | | 2010-02-01 | 24 | | 2010-03-01 | 23 | | 2010-04-01 | 28 | | 2010-05-01 | 30 | I need to find if the last three consecutive months have increased in value. How can I get SQL to chec...

Parsing an xs:duration datatype into a Python datetime.timedelta object?

As per the title, I'm trying to parse an XML file containing an xs:duration data type. I'd like to convert that into a Python timedelta object, which I can then use in further calculations. Is there any built-in way of doing this, similar to the strptime() function? If not, what is the best way to achieve this? ...

How best to convert CakePHP date picker form data to a PHP DateTime object?

I'm doing this in app/views/mymodel/add.ctp: <?php echo $form->input('Mymodel.mydatefield'); ?> And then, in app/controllers/mymodel_controller.php: function add() { # ... (if we have some submitted data) $datestring = $this->data['Mymodel']['mydatefield']['year'] . '-' . $this->data['Mymodel']['mydatefield'...

date in future for Rails

Hello, I am trying to make a validation that will validate that the entered date is in future and that the selected date is in the next 7 days. In order to validate if the date is in future I use; valid_until.future? and this one works fine, but to make a validation to check if the date selected is withing 7 days from now? ...

String formatting help

I have this: 2010-04-08T01:01:00Z I want to remove the 'T' and everything behind it as well. Also I would like to rewrite the date into this format: 08-04-2010 How can I do this the easiest way? Thanks ...

Excel/SQLite date serial numbers

How can I get SQLite to convert excel-type serial numbers to dates, e.g. I want the integer 40074 in a table to somehow get the date 18-Sept-2009? The dates are already in SQLite. ...

ASP.Net MVC, strongly typed view with DateTime not accepted?

Hi all, I wish to create a view like <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %> but I get an error saying that DateTime must be a reference type in order to use for parameter TModel. Fair enough, but I google plenty of examples that implement just what I try to achieve. Any clues as to ...

python get time in minutes

import datetime start = datetime.datetime(2009, 1, 31) end = datetime.datetime(2009, 2, 1) print end-start >>1 day, 0:00:00//output How to get the output in minutes Thanks, ...

Add and Subtract Time

I have always had a problem with adding and subtracting time like for an example: 10h:34min + 07h:46min ----------- XX:XX ...

Type hinting and optional attributes in PHP

I have a class method that deals with dates: public function setAvailability(DateTime $start, DateTime $end){ } Since item availability can have lower limit, upper limit, both or none, I'd like to make setAvailability() accept NULL values as well. However, the NULL constant violates the type hinting: $foo->setAvailability(NULL, $end)...

Working with timezones in C

Hi, I'm currently migrating some of my code from Cocoa (Apple's Objective-C API) to C, in order to make it available for other operating systems, such as GNU/Linux. In Cocoa, there were many great things like creating NSTimeZone objects from their string descriptors using timeZoneWithAbbreviation:. This allowed me to use values like "E...

Python datetime to Unix timestamp

I have to create an "Expires" value 5 minutes in the future, but I have to supply it in UNIX Timestamp format. I have this so far, but it seems like a hack. def expires(): '''return a UNIX style timestamp representing 5 minutes from now''' epoch = datetime.datetime(1970, 1, 1) seconds_in_a_day = 60 * 60 * 24 five_minute...

sql - datetime variable versus string representation of datetime variable

I have a query that takes too long to respond when the search parameter happens to be a varchar datatype with date. However, if i convert varchar to datetime variable, the query runs fine. For ex: This takes too long. select count(id) from names where updateddate > '1/5/2010' This runs fine. declare @dateparam datetime set @...

How do you obtain a formatted date and time for the current locale in C?

What C function should I call to obtain a formatted date and time for the locale where the program is being executed? I'm asking this question because I have run into a problem using the ClamAV daemon API. The VERSION command returns the date and time of the latest virus definitions, but the code uses a call to ctime to format it. As fa...

How to convert a "dd/mm/yyyy" string to datetime in SQL Server?

I tried this SELECT convert(datetime, '23/07/2009', 111) but got this error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. However SELECT convert(datetime, '07/23/2009', 111) is OK though How to fix the 1st one ? ...

Python sum up time

In python how to sum up the following time 0:00:00 0:00:15 9:30:56 Thanks.. ...