I have users entering a date and a time zone (e.g. "America/Los Angeles") for that date and I'd like to convert that to UTC but to do that I need the utc offset for the time on that date.
I can easily convert a date to the offset for the time zone if I already know the UTC date but I need the other way around...
The utc offset can change depending on the date due to daylight saving so I need a way to enter a date and a timezone and get back the offset from UTC using that.
Knowing the most recent switch from PST to PDT On march 11 at 2AM I tried using
var tzOffset = moment.tz("3/11/2018 3:00 AM", "America/Los_Angeles").utcOffset();
document.write('utc offset is : ' + tzOffset + '<br/>') ;
but that gives 480 when the correct answer is 420
I can get the correct answer 420 if I use parseZone like so:
var tzOffset2 = moment.parseZone("3/11/2018 3:00 AM -07:00").utcOffset();
document.write('utc offset2 is : ' + tzOffset2 + '<br/>') ;
but that means I need to already know the -7 offset that I'm trying to find...
So how do I find the utcOffset for a specific date/time like "3/11/2018 3:00 AM" and timezone like "America/Los_Angeles"? Thanks
Your input is not in a ISO 8601 or RFC 2822 format recognized by moment(String), so you have to specify the format as second parameter using moment(String, String) (please note that, as docs states: The moment.tz constructor takes all the same arguments as the moment constructor, but uses the last argument as a time zone identifier.)
Your code could be like the following:
var tzOffset = moment.tz("3/11/2018 3:00 AM", "D/M/YYYY h:mm A", "America/Los_Angeles").utcOffset();
document.write('utc offset is : ' + tzOffset + '<br/>') ;
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.14/moment-timezone-with-data-2012-2022.min.js"></script>
I have several rows in my table like below:
row1: abc changed on 12 November, 2008 11:30 AM and its abc..region1
row2: defg updated 14 January, 2012 08:20 PM ......region2
row3: ghijkl corrected by 18 august, 2013 9:30 AM ..something..region3
My requirement is as follows:
All the above dates are in EST time zone and date format is exactly as above and does not change.
I want to update the dates in these rows from EST to different time zones as per the region in that row, and the format should be changed to something like 12 dec 2016 7:30 AM.
So the query I framed is (taking row1 as example) as below:
select regexp_replace(
'abc changed on 12 November, 2008 11:30 AM and its abc..region1',
'([0-9]{2})([[:blank:]]) (January|February|March|April|May|June|July|August|September|October|November|December)(,[[:blank:]])([0-9]{4})([[:blank:]])([0-9]{2}:[0-9]{2})([[:blank:]])(AM|PM)','\1-\3-\5 \7 \9',1,0,'i')
output:
abc changed on 12-November-2008 11:30 AM and its abc..region1
So I am happy with the above query till now because I get a string
with the formatted date. Even though this is not the final date
format, I can use this date to pass to some function which converts
this date according to the region do some processing and fianlly
return a date type.For the same purpose I add to_date in the above
query:
select regexp_replace(
'abc changed on 12 November, 2008 11:30 AM and its abc..region1',
'([0-9]{2})([[:blank:]]) (January|February|March|April|May|June|July|August|September|October|November|December)(,[[:blank:]])([0-9]{4})([[:blank:]])([0-9]{2}:[0-9]{2})([[:blank:]])(AM|PM)',
substr('\1-\3-\5 \7 \9',1),
1,0,'i')
output:
abc changed on 12-November-2008 11:30 AM and its
abc..region1 --> works fine till here
Now I am adding to_date to convert the date string type to real date
type to do some processing on it:
select regexp_replace(
'abc changed on 12 November, 2008 11:30 AM and its abc..region1',
'([0-9]{2})([[:blank:]]) (January|February|March|April|May|June|July|August|September|October|November|December)(,[[:blank:]])([0-9]{4})([[:blank:]])([0-9]{2}:[0-9]{2})([[:blank:]])(AM|PM)',
to_date(substr('\1-\3-\5 \7 \9',1),'dd-mon-yyyy HH:MI AM'),
1,0,'i')
This query is giving me an error:
ORA-01858: a non-numeric character found where a numeric was expected
I checked whether wrong parameters were being passed to
to_date(), and fired the query below, but it worked fine.
Select to_date('12-November-2008 11:30 AM','dd-mon-yyyy HH:MI AM')
from dual;
output:
12-Nov-2008
(I am not worried with the timestamp because itnternall it will be anyways in this date)
To avoid confusion I have numbered the substrings of the regular expression above:
([0-9]{2})-->1 ([[:blank:]])-->2
(January|February|March|April|May|June|July|August|September|October|November|December)-->3
(,[[:blank:]])-->4 ([0-9]{4})-->5 ([[:blank:]])-->6
([0-9]{2}:[0-9]{2})-->7 ([[:blank:]])-->8 (AM|PM)-->9
select regexp_replace(
'abc changed on 12 November, 2008 11:30 AM and its abc..region1',
'([0-9]{2})([[:blank:]]) (January|February|March|April|May|June|July|August|September|October|November|December)(,[[:blank:]])([0-9]{4})([[:blank:]])([0-9]{2}:[0-9]
{2})([[:blank:]])(AM|PM)','\1-\3-\5 \7 \9',1,0,'i')
Assuming your string always has the date in it in that particular format (and that there are no invalid dates etc etc) then the following should work for you:
WITH sample_data AS (SELECT ' the date is 12 November, 2008 11:30 AM' str FROM dual UNION ALL
SELECT 'Here''s a date of 1 March, 2015 1:43 pm' str FROM dual UNION ALL
SELECT '1 February,2016 9:43 AM' str FROM dual UNION ALL
SELECT 'And again it''s 21 May, 2016 9:43 AM and a little bit extra' str FROM dual)
SELECT str,
to_date(regexp_replace(str, '^.*?([[:digit:]]{1,2} [[:alpha:]]{3,9}, ?[[:digit:]]{4} [[:digit:]]{1,2}\:[[:digit:]]{2} (A|P)M).*$', '\1', 1, 1, 'i'), 'dd Month yyyy, hh:mi am') dt
FROM sample_data;
STR DT
---------------------------------------------------------- -------------------
the date is 12 November, 2008 11:30 AM 12/11/2008 11:30:00
Here's a date of 1 March, 2015 1:43 pm 01/03/2015 13:43:00
1 February,2016 9:43 AM 01/02/2016 09:43:00
And again it's 21 May, 2016 9:43 AM and a little bit extra 21/05/2016 09:43:00
The regular expression can be broken down as follows:
^.*? - match any character (except new line) from the start of the line as few times as possible, which may be 0 or more.
([[:digit:]]{1,2} [[:alpha:]]{3,9}, ?[[:digit:]]{4} [[:digit:]]{1,2}\:[[:digit:]]{2} (A|P)M) - this is the pattern we're looking for, and which we'll use to replace the whole string with (this is aliased as \1, which we can then pass into the replace string parameter).
.*$ - match any character up to the end of the string
The second part of the pattern can be further broken down as:
[[:digit:]]{1,2} - one or two digits
- a single space character
[[:alpha:]]{3,9} - three to nine letters (upper or lower case)
, ? - a comma followed by 0 or 1 spaces
[[:digit:]]{4} - four digits
- a single space character
[[:digit:]]{1,2} - one or two digits
\: - a single colon character
[[:digit:]]{1,2} - two digits
- a single space character
(A|P)M - either the letter A or P followed by an M
This should do the trick for you:
WITH sample_data AS (SELECT 'abc changed on 12 November, 2008 11:30 AM and its abc..region1' str FROM dual UNION ALL
SELECT 'defg updated 14 January, 2012 08:20 PM ......region2' str FROM dual UNION ALL
SELECT 'ghijkl corrected by 18 august, 2013 9:30 AM ..something..region3' str FROM dual)
SELECT str,
regexp_replace(str,
'(^.*?)(([[:digit:]]{1,2}) (January|February|March|April|May|June|July|August|September|October|November|December), (?[[:digit:]]{4} [[:digit:]]{1,2}\:[[:digit:]]{2} (A|P)M))(.*$)',
'\1\3-\4-\5\7', 1, 1, 'i') dt
FROM sample_data;
STR DT
------------------------------------------------------------------- --------------------------------------------------------------------------------
abc changed on 12 November, 2008 11:30 AM and its abc..region1 abc changed on 12-November-2008 11:30 AM and its abc..region1
defg updated 14 January, 2012 08:20 PM ......region2 defg updated 14-January-2012 08:20 PM ......region2
ghijkl corrected by 18 august, 2013 9:30 AM ..something..region3 ghijkl corrected by 18-august-2013 9:30 AM ..something..region3
I have two dates
strFrom = formatDateTime("11:15",4)
strTo = formatDateTime("16:30",4)
I want to generate a script so that get every quarter from strFrom to StrTo
11:15
11.30
11.45
12.00
12:15
12:30
12:45
13:00
13:15
...
...
...
16:00
16:30
First you need convert to a datetime, then you need to increment the minutes in a loop.
<%
strFrom = formatDateTime("11:15",4)
strTo = formatDateTime("16:30",4)
dteFrom=CDate(strFrom)
dteTo=CDate(strTo)
Response.write(strFrom & "<br>")
Do While (dteFrom < dteTo)
dteFrom=DateAdd("n",15,dteFrom)
Response.write(formatDateTime(dteFrom,4) & "<br>")
Loop
%>
I am having two Datatables : dt1 and dt2. Now dt1 is having datacolumn something like:
Monday | Wednesday | Thursday
but doesnt have anything in datarow yet.
Now,in dt2,the data is something like:
StartTime | EndTime
7:10 | 8:00
8:00 | 9:00
9:00 | 10:00
I want to merge both datatable so that i can get Datatable something like:
StartTime | EndTime | Monday | Wednesday | Thursday
7:10 | 8:00
8:00 | 9:00
9:00 | 10:00
Please help me :(
This project is to design School timetable.
Any help will be appreciated.
Thanks
Also,,,suggest me that is it good to use datatable?or should go for table control for Timetable
you can copy the columns without rows like this:
foreach (DataColumn dc in dt1.Columns)
{
dt2.Columns.Add(dc.ColumnName, dc.DataType);
}
It seems that VB6 can't correctly compare dates in some situations. Are there any solutions to this?
Private Sub CheckDate()
date1 = #7/6/2010 2:00:00 PM#
Debug.Print "Date 1: " + CStr(date1)
date2 = DateAdd("h", -8, #7/6/2010 10:00:00 PM#)
Debug.Print "Date 2: " + CStr(date2)
Debug.Print "Equal? " + CStr(date1 = date2)
End Sub
The correct output should be:
Date 1: 7/6/2010 2:00:00 PM
Date 2: 7/6/2010 2:00:00 PM
Equal? True
but the real output is:
Date 1: 7/6/2010 2:00:00 PM
Date 2: 7/6/2010 2:00:00 PM
Equal? False
Is there any way around this, or is there any way to avoid this situation (whatever it is)?
You should use the DateDiff function. It can be adapted to whatever level of precision you need.
http://www.vb6.us/tutorials/learn-howto-use-visual-basic-datediff-function
"Treat your dates as doubles" which they are behind the scene
Debug.Print "Equal? " + CStr(Abs(date1 - date2) < 0.000000001)