I want to write the current date in the following format in VB.net:
Tue, 27 Jul 2010 00:00:00 GMT+02:00
Any help would be appreciated.
Perhaps simply:
Date.Now.ToString("R") ' Fri, 14 Nov 2014 12:32:18 GMT
The RFC1123 ("R", "r") Format Specifier
Related
PostgresSql - Filtering data between dates which in format like Mon Jun 20 2022 10:04:01 GMT+0530 (India Standard Time). I want to filter data between 2 dates
i.stack.imgur.com/Hu91J.jpg
I'm using snowflake dates.
I have date in weird pattern (output from database):
Wed Apr 21 2021 22:11:32 GMT+0300 (Israel Daylight Time)
I need to parse it as datetime- YY-MM-DD HH:MM:SS.
if I try this out:
SELECT TO_TIMESTAMP_NTZ('Wed Apr 21 2021 22:11:32 GMT+0300 (Israel Daylight Time)', 'YY:MM:DD
HH:MM:SS')
I get this error:
SQL Error [100096] [22007]: Can't parse 'Wed Apr 21 2021 22:11:32 GMT+0300 (Israel Daylight Time)' as
timestamp with format 'YY:MM:DD HH:MM:SS'
and so on in every function I tried!!
(TO_TIMESTAMP_NTZ, TO_TIMESTAMP_LTZ, TO_TIMESTAMP_TZ, TO_TIMESTAMP, TO_DATETIME, TO_DATE, TO_TIME).
any idea?
Using the values at Timestamp Formats, and trimming the string down we can get the following working
SELECT TO_TIMESTAMP_NTZ('Wed Apr 21 2021 22:11:32', 'DY MON DD YYYY HH:MM:SS');
adding the timezone back in with
SELECT TO_TIMESTAMP_NTZ('Wed Apr 21 2021 22:11:32 GMT+0300', 'DY MON DD YYYY HH:MM:SS GMTTZHTZM');
this works, but gives a NoTimeZone value, when the value has a timezone, so purhaps NTZ is not what you wanted.
But the (Israel Daylight Time) part is throwing us for a loop, so lets get rid of that with a REGEX_SUBSTR
SELECT 'Wed Apr 21 2021 22:11:32 GMT+0300 (Israel Daylight Time)' as in_str
,REGEXP_SUBSTR( in_str , '(.*) \\(',1,1,'c',1) as regex_str
,TO_TIMESTAMP_NTZ(regex_str, 'DY MON DD YYYY HH:MM:SS GMTTZHTZM') as time
;
gives:
IN_STR
Wed Apr 21 2021 22:11:32 GMT+0300 (Israel Daylight Time)
REGEX_STR
Wed Apr 21 2021 22:11:32 GMT+0300
TIME
2021-11-21 22:00:32.000
I have a column varchar type with dates like:
Fri Mar 3 12:55:17 EST 2017
Thu Jul 27 10:12:07 EDT 2017
Fri Jul 21 12:11:35 EDT 2017
Wed Jan 31 13:15:34 EST 2018
And I would like to return just the date and time something like:
03/03/2017 12:55:17
07/27/2017 10:12:07
07/21/2017 12:11:35
01/31/2018 13:15:34
I tried several ways with substring and convert statement but nothing work.
Any assistance in this regard will be greatly appreciated.
Perhaps something like this
Example
Declare #YourTable table (SomeCol varchar(50))
Insert Into #YourTable values
('Fri Mar 3 12:55:17 EST 2017'),
('Thu Jul 27 10:12:07 EDT 2017'),
('Fri Jul 21 12:11:35 EDT 2017'),
('Wed Jan 31 13:15:34 EST 2018')
Select *
,AsDateTime = try_convert(datetime,substring(SomeCol,4,len(SomeCol)-11)+right(SomeCol,4))
From #YourTable
Returns
SomeCol AsDateTime
Fri Mar 3 12:55:17 EST 2017 2017-03-03 12:55:17.000
Thu Jul 27 10:12:07 EDT 2017 2017-07-27 10:12:07.000
Fri Jul 21 12:11:35 EDT 2017 2017-07-21 12:11:35.000
Wed Jan 31 13:15:34 EST 2018 2018-01-31 13:15:34.000
I have referred to the psql documentation and came up with this query.
SELECT to_timestamp('Tue Aug 30 2016 04:07:13 GMT+0530 (IST)', 'Dy MON DD YYYY HH24:MI:SS');
This date time string Tue Aug 30 2016 04:07:13 GMT+0530 (IST) is what I got from MongoDB printjson(createdAt).
The above postresql doesn't seem to work correctly for all offsets.
I tried this
select to_timestamp('Tue Aug 30 2016 04:07:13 GMT+0530 (IST)', 'Dy MON DD YYYY HH24:MI:SS "GMT"OF "(IST)"');
But I get this error ``ERROR: "TZ"/"tz"/"OF" format patterns are not supported in to_date`.
How to convert to psql timestamptz format from this string Tue Aug 30 2016 04:07:13 GMT+0530 (IST) ?
It looks an ugly wheel and requires such replace for each unrecognized offset, but it works. For your sample replace 'GMT+0530 (IST)' to 'GMT+05:30' and it will be picked up:
t=# select replace('Tue Aug 30 2016 04:07:13 GMT+0530 (IST)','GMT+0530 (IST)','GMT+05:30')::timestamptz;
replace
------------------------
2016-08-30 09:37:13+00
(1 row)
t=# select replace('Tue Aug 30 2016 14:07:13 GMT+0530 (IST)','GMT+0530 (IST)','GMT+05:30')::timestamptz;
replace
------------------------
2016-08-30 19:37:13+00
(1 row)
update: depending on your timezone result can be confusing:
t=# set timezone TO 'GMT-5:30'; SET
t=# select replace('Tue Aug 30 2016 14:07:13 GMT+0530 (IST)','GMT+0530 (IST)','GMT+05:30')::timestamptz;
replace
---------------------------
2016-08-31 01:07:13+05:30
(1 row)
to check if it is right, use:
t=# select replace('Tue Aug 30 2016 14:07:13 GMT+0530 (IST)','GMT+0530 (IST)','GMT+05:30')::timestamptz at time zone 'UTC';
timezone
---------------------
2016-08-30 19:37:13
(1 row)
There is table called t1, and there are columns id, created_at, text, for example, as following table:
id created text
1 Thu Jun 30 01:00:57 +0000 2016 I like this movie1
2 Thu Jun 30 02:59:57 +0000 2016 I like this movie2
3 Thu Jun 30 03:49:57 +0000 2016 I like this movie3
4 Thu Jun 30 04:59:50 +0000 2016 I like this movie4
5 Thu Jun 30 05:39:57 +0000 2016 I like this movie5
6 Thu Jun 30 06:39:57 +0000 2016 I like this movie6
7 Thu Jun 30 06:29:57 +0000 2016 I like this movie6
8 Thu Jun 30 07:09:57 +0000 2016 I like this movie7
9 Thu Jun 30 07:39:57 +0000 2016 I like this movie8
10 Thu Jun 30 08:39:57 +0000 2016 I like this movie9
11 Thu Jun 30 09:39:57 +0000 2016 I like this movie10
12 Thu Jun 30 10:29:57 +0000 2016 I like this movie11
13 Thu Jun 30 11:29:57 +0000 2016 I like this movie12
12 Thu Jun 30 12:29:57 +0000 2016 I like this movie13
I want to select data separated by hour time.
For example, I want to select all the data that hour is less or equal 06, then I want to select the data that hour is more than 07. Since the data of column is datetime form: Thu Jun 30 12:29:57 +0000 2016, I don't know how to deal with this. Thanks for your help!
The sql is presto(presto sql):
select id, created, text from t1 where created_at <= 6
You could use datepart for this if you are using mssql:
select
id,
created,
text
from
t1
where
datepart(hour, created) <= 6
References:
DATEPART (Transact-SQL)
I done it, use the hour(datestamp)can solve it.
select id, created, text from t1 where hour(created_at) <= 6