Adding Epochtime variable in Excel query

b0unce

Board Regular
Joined
Apr 22, 2009
Messages
75
Hello,

I want to create a connection between Yahoo Finance certain report to my Excel spreadsheet and ran into one problem.
My source code in advance editor seems like this:

...
Source = Csv.Document(Web.Contents("https://query1.finance.yahoo.com/v7/finance/download/^NDX?period1=1623306860&period2=1654848352&interval=1d&events=history&includeAdjustedClose=true"),[Delimiter=",", Columns=7, Encoding=65001, QuoteStyle=QuoteStyle.None]),
...

What I need to do is to change fixed value of period2 in this code so that it shows current Epoch time value. I have the formula for Epoch time: Duration.TotalSeconds(DateTime.LocalNow() - #datetime(1970,1,1,0,0,0)))
It works on separate table, but I cannot make it work in my initial source file. Could anyone please help?
Thank you in advance!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Power Query:
    p2 = Number.ToText(Number.Round(Duration.TotalSeconds(DateTimeZone.UtcNow() - DateTimeZone.FromText("1970-01-01T00:00:00Z")))),

    URL = Text.Combine({"https://query1.finance.yahoo.com/v7/finance/download/^NDX?period1=1623306860&period2=",p2,"&interval=1d&events=history&includeAdjustedClose=true"}),
And use URL as the Web.Contents argument.
 
Upvote 0
Solution
Power Query:
    p2 = Number.ToText(Number.Round(Duration.TotalSeconds(DateTimeZone.UtcNow() - DateTimeZone.FromText("1970-01-01T00:00:00Z")))),

    URL = Text.Combine({"https://query1.finance.yahoo.com/v7/finance/download/^NDX?period1=1623306860&period2=",p2,"&interval=1d&events=history&includeAdjustedClose=true"}),
And use URL as the Web.Contents argument.
Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top