Tuesday, December 2, 2008

sql: easy datetime formatting to varchar

convert(varchar, FIELD_NAME, FORMAT_NUMBER_FROM_CHART)

http://msdn.microsoft.com/en-us/library/aa226054(SQL.80).aspx

sql: get just the hour from a datetime

SELECT DATEADD(hh, 13, DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())))

probably a fancier way to keep the hour information, but you can just in an hour variable there to add it back in.

replace getdate() with your date field

Wednesday, October 29, 2008

SQL: Insert from another table

INSERT INTO Table1 (ab)     
SELECT c, d     
FROM Table2     
WHERE c = 'something'

Tuesday, September 30, 2008

SQL 2005: Delete Records Using Another Table

DELETE tobeupdated_table FROM tobeupdated_table  a
WHERE a.tableID = @ID_in
       AND a.otherTableID IN 
           ( SELECT otherTableID  FROM otherTable b
                    WHERE b.someField = @someValue_in
           );

Monday, September 22, 2008

C#: DataTable row conversions.

double value = double.Parse(dr["value"].ToString());

This would parse a value in a datatable field as a double.

Wednesday, August 27, 2008

Python: Datetime Math

#start code
import datetime
from datetime import datetime as dt
oneDay = datetime.timedelta(days=1)
tomorrow = dt.today()+oneDay
kmlTimeFormat = tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ")
#end code

timedelta resides in the datetime module
today() resides in the datetime.datetime module

then add timedelta (can use months, hours, days, ...) to your datetime.datetime object

I added the kml date string format because thats what i am working on at the moment.


more info

Thursday, July 31, 2008

Javascript: Confirmation Alert

if ( confirm("are you sure?") )
alert( 'you chose yes' );
else
alert("you chose no");