Well here is a nice function to get the current unix timestap in C#:
public double unix_timestamp() {
TimeSpan unix_time = (System.DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
return unix_time.TotalSeconds;
}
Twit This Post!
Like this:
Be the first to like this post.
Okay. Previously we converted datetime type values into unix timestamps. Now here is how to convert them back.
@datetime = DATEADD(second, @timestamp, {d '1970-01-01})
Where @timestamp is the unix timestamp we want to convert.
The {d ‘yyyy-mm-dd’} is an ODBC escape sequence.
Read more…
Like this:
Be the first to like this post.
This is a really simple Transact-SQL function to make it easier to convert MS SQL’s datetime datatype to Unix Timestamps.
Converting a datetime to unix timestamp is easy, but involves error prone typing the following:
@timestamp=DATEDIFF(second,{d '1970-01-01'},@datetime)
Where
@datetime is the datetime value you want to convert.
The {d ‘yyyy-mm-dd’} notation is
an ODBC escape sequence.
Read more…
Like this:
Be the first to like this post.
Recently I was looking for a way to get the current date and time through an SQL query in MS SQL Server 2005. I know that I can do that with the function now() in MySQL and PostgreSQL, but I couldn’t find this function for MS SQL. After digging around I found Matt Faus’s blog which had a post that wrote about the thing I wanted.
Matt Faus’s blog: MS SQL Server Transact-SQL NOW() Function
So to get the current datetime use:
SELECT GETDATE();
GO
Link to the MSDN article (SQL Server 2008): http://msdn2.microsoft.com/en-us/library/ms188383.aspx
Link to the MSDN article (SQL Server 2005): http://msdn.microsoft.com/en-us/library/ms188383(SQL.90).aspx
Also there is a function CURRENT_TIMESTAMP(). Usage is:
SELECT CURRENT_TIMESTAMP();
GO
Docs for this (SQL Server 2005)
Twit This Post!












Like this:
Be the first to like this post.
This is just an update of the previous PL/PGSQL function.
CREATE OR REPLACE FUNCTION "schemanema"."reset_sequence" (tablename text) RETURNS "pg_catalog"."void" AS
$body$
DECLARE
idx integer DEFAULT 1;
cmd varchar;
BEGIN
EXECUTE 'SELECT id FROM "schemaname".'
|| tablename
|| ' ORDER BY id DESC LIMIT 1' INTO idx;
IF NOT FOUND THEN
idx = 1;
ELSE
idx = idx + 1;
END IF;
cmd = 'SELECT setval( ''schemaname.'
|| tablename
|| '_id_seq'', '
|| idx
|| ', false)';
EXECUTE cmd;
END;
$body$
LANGUAGE 'plpgsql';
Like this:
Be the first to like this post.
Working with jQuery is really fun. I made a little handy plugin to make folding and unfolding parts of a page easier.
Read more…
Like this:
Be the first to like this post.
Recent Comments