Convert the date from PST to IST and output the difference in hour - excel

Is there any way to automatically convert PST Date in to IST date. When I put date in column E and F I have dates in PST time zone. I want to convert in IST time zone. after i want output in column G. the difference between two dates.
I have solved this with excel formula but I want this to done with VBA.
For eg.
> E F G
1/14/2016 2:49:00 PM 1/14/2016 2:57:00 PM 0:08
1/14/2016 2:45:00 PM 1/14/2016 2:59:00 PM 0:09

Consider:
Sub qwerty()
Dim pst As Date, ist As Date
pst = DateSerial(2016, 1, 14) + TimeSerial(14, 49, 0)
ist = pst + TimeSerial(13, 30, 0)
MsgBox pst & vbCrLf & ist
End Sub

String string = "December 16, 2016 12:10:05 PST";
DateFormat format = new SimpleDateFormat("MMMM dd, yyyy HH:mm:ss z", Locale.ENGLISH);
Date date = format.parse(string);
System.out.println(date);
Output : Sat Dec 17 01:40:05 IST 2016

Related

Start of day calculation using tz pytz timezone

We are interested in calculating a date using input fields that have month values and day values. For example the year_sent can be 2021, month_sent can be 0 and date_sent can be 31 for the date Jan 31st, 2021.
tz = pytz.timezone(obj_timezone)
timestamp_current_tz_start_of_day = datetime(year_sent, month_sent, date_sent, 0, 0, tzinfo=tz)
timestamp_current_start_of_day = int((timestamp_current_tz_start_of_day - datetime(1970, 1, 1,0,0, tzinfo=pytz.utc)).total_seconds() * 1000)
We expect the timestamp_current_start_of_day to be Jan 31st, 2021 12:00am Timezone. But instead we get Jan 31st, 2021, 12:53am Timezone.
What are we doing wrong?

How to parse String to DateTime using ParseExact [duplicate]

I'm using RSS feeds from multiple sources and I'm sorting the feeds by date. However, the dates I receive are in different time zones.
This is the format of some of the date strings that I get:
Wed 08 Dec 2021 01:40:31 -0500
Wed 08 Dec 2021 11:11:19 -0600
The "-500' indicates the time zone which is UTC-5. I need to use that "-0500" to convert this string into a date and the date needs to be only in UTC.
Basically from "Wed 08 Dec 2021 01:40:31 -0500" to "12/08/2021 06:40:31"
I've managed to split the string up to sort by date but because of the time difference, it doesn't really help.
Is there coding which I can use to convert the string as-is into date and only UTC time? Or is there just a place where I can start?
Thank you in advance.
Using DateTime.ParseExact, you specify a format to convert from, and that can include "zzz" for the timezone offset. You can also specify that you want the result in UTC:
Dim s = "Wed 08 Dec 2021 01:40:31 -0500"
Dim d = DateTime.ParseExact(s, "ddd dd MMM yyyy HH:mm:ss zzz", Nothing, Globalization.DateTimeStyles.AdjustToUniversal)
Console.WriteLine(d.ToString("yyyy-MM-dd HH:mm:ss"))
Console.WriteLine(d.Kind.ToString())
Outputs:
2021-12-08 06:40:31
Utc
Of course, format the result as you desire.
Alternatively, if you need to, you can keep the offset by using a DateTimeOffset structure and adjust it to UTC for representation as a string:
Dim s = "Wed 08 Dec 2021 01:40:31 -0500"
Dim d = DateTimeOffset.ParseExact(s, "ddd dd MMM yyyy HH:mm:ss zzz", Nothing)
Console.WriteLine(d.ToUniversalTime.ToString("yyyy-MM-dd HH:mm:ss"))
Outputs:
2021-12-08 06:40:31

Converting integer to time format in excel

Date
19112018
19112016
19112015
19112013
I have a column named Date.
I want to convert 19112018 to 2019-11-20 18:00
19 means year 2019
11 month
20 days
18 is hour
Thanks .
Use the following formula:
=DATE(20&LEFT(A2,2),MID(A2,3,2),MID(A2,5,2))+RIGHT(A2,2)/24
Or:
=--(20&REPLACE(REPLACE(REPLACE(A2,7,0," "),5,0,"-"),3,0,"-")&":00")
Then format the output cell:
yyyy-mm-dd hh:mm

How to convert time format from Moment to D3?

In Node, I am using Moment for time and on the front-end I am using the D3 package. For moment, I will get a time of 1429588800 which is converts to "Tue Apr 21 2015 00:00:00 GMT-0400". But in D3, I get "05/031976". This is with the format "%x".
The problem I believe is that you use seconds (unix timestamp). If you multiply it by 1000 it should work. Here are some tests for you
var value = 1429588800;
var f = d3.time.format("%x");
var date = new Date(value*1000);
var moment_date = moment.unix(value);
console.log('date',date); //date Tue Apr 21 2015 00:00:00 GMT-0400 (Eastern Daylight Time)
console.log('moment date',moment_date.format()); //moment date 2015-04-21T00:00:00-04:00
console.log('d3 + moment date',f(moment_date.toDate())); //d3 + moment date 04/21/15
console.log('d3 + date',f(date)); //d3 + date 04/21/15

Excel Doc Sum row b where row a in between dates

I have a google spreadsheet having data as below
Date SomeVal
Aug 01, 2013 1
Aug 02, 2013 5
And so on. I want to have another sheet with Monthly grouping as follows(This is what I want in the end but unable to get here)
Month Total
Apr 2013 200
May 2013 300
I tried following but could not get correct result
=SUMIFS(Sheet1!B:B,Sheet1!A:A,ʺ> Aug 1, 2013ʺ) //Returns SUM(B:B) as all dates are above Aug 1 2013
=SUMIFS(Sheet1!B:B,Sheet1!A:A,ʺ< Jun 1, 2014ʺ) //Returns 0 which is wrong
This is what I expected to get
sum for which date > Aug 2013
sum for which date < Jun 2014
My date format is Mon DD, YYYY
Any idea Where I am wrong
This format works for me
Raw Data in Sheet2
(Column A) (Column B)
Date Val
----------- ---------
7/1/2013 1
7/2/2013 2
7/3/2013 3
7/4/2013 4
And so on and so forth up until 2/9/2016 (as long as they are date values you can format them however you want)
Summed Data in Sheet1
(Column A) (Column B)
Month Total
---------- ---------
Jul 2013 496
Aug 2013 1457
Sep 2013 2325
Oct 2013 3348
Nov 2013 4155
So on and so forth for each month that I want, using this formula. Each month is formatted as MMM YYYY, and the date is the first of the month (7/1/2013, 8/1/2013, etc...)
=SUMIFS(Sheet2!$B:$B,Sheet2!$A:$A,">="&Sheet1!$A2,Sheet2!$A:$A,"<"&Sheet1!$A3)
This says
Sum the range in Sheet 2 Column B where:
The date in column A of that row is greater than the first of the month supplied
The date in column A of that row is less than the first of the month afterwards

Resources