Trying to find a way to list all friday dates between 2 dates in powershell [closed] - list

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How to identify a list of dates with a specific day of the week between 2 dates in Powershell

No problem, it's fairly straightforward:
$date = [datetime]::parseexact('07-Feb-20', 'dd-MMM-yy', $null)
$date2 = [datetime]::parseexact('28-Feb-20', 'dd-MMM-yy', $null)
$fridays = 1..($date2 - $date).Days | % {$date.AddDays($_)} | ? {$_.DayOfWeek -eq 'Friday'}
Just make sure you put your dates in correctly! There's likely a more succinct way to do it.

Every PowerShell [datetime] object contains a .DayOfWeek parameter which will tell you the day of the week. You can interate through the date items with another [datetime] feature, the .AddDays() method. So something like this:
$StartDate = [datetime]'datehere'
$EndDate = [datetime]'datehere'
$ThisDate = $StartDate
$AllFridays = #()
While ($ThisDate -le $EndDate)
{
If ($ThisDate.DayOfWeek -eq 'Friday') { $AllFridays += $ThisDate }
$ThisDate.AddDays(1)
}
This was just a first crack. Obviously, you could find the first friday, and then add days 7 at a time until you were past the End date, but I leave that optimization as an exercise for the reader. :)

Related

Regular Expressions - Snowflake [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
enter image description hereI am trying to get text till the fourth "\n \n" from the below text. Can you please help me to write the snowflake expression for this issue.
Hello Jeffrey,\n \nWe have not heard from you yet. I hope all is well with you.\n \nChecking in to gather your Goosehead approved office location address, so we can add you to our database here at ERGOS. Once added here, we can schedule your laptop setup.\n \nGoosehead requires all agents to be onboarded by ERGOS so that we can provide IT support as well as get your laptop in our database. \n \nDo you have a laptop ready for setup?
so every thing up to the first \n \n can be fetched with regexp_substr via:
select
regexp_substr(column1, '.*\n \n') as match
from values
('Hello Jeffrey,\n \nWe have not heard from you yet. I hope all is well with you.\n \nChecking in to gather your Goosehead approved office location address, so we can add you to our database here at ERGOS. Once added here, we can schedule your laptop setup.\n \nGoosehead requires all agents to be onboarded by ERGOS so that we can provide IT support as well as get your laptop in our database. \n \nDo you have a laptop ready for setup?');
MATCH
Hello Jeffrey,
now, if we add a group around that ( ) and ask for 4 matches {4}, and swap to a smaller sample text, to make things less ugly for the output
select
regexp_substr(column1, '(.*\n \n){4}') as match
from values
('1111\n \n222222222222222\n \n3333333333333333\n \n44444444444444444\n \n55555555555555555555555');
gives:
MATCH
1111 222222222222222 3333333333333333 44444444444444444
if you are expecting the \n in the output:
then
select
column1,
regexp_substr(column1, '[^\\\\]+\\\\n \\\\n') as match
from values
('1111\\n \\n22222\\n \\n33333333\\n \\n4444444\\n \\n55555\\n \\66666\\n \\n7777');
shows how they need to be encoded in the SQL to output, and thus how to encode the match.
these matches greedy and gives:
COLUMN1
MATCH
1111\n \n22222\n \n33333333\n \n4444444\n \n55555\n \66666\n \n7777
1111\n \n
thus putting the grouping back in:
select
column1,
regexp_substr(column1, '([^\\\\]+\\\\n \\\\n){4}') as match
from values
('1111\\n \\n22222\\n \\n33333333\\n \\n4444444\\n \\n55555\\n \\66666\\n \\n7777');
COLUMN1
MATCH
1111\n \n22222\n \n33333333\n \n4444444\n \n55555\n \66666\n \n7777
1111\n \n22222\n \n33333333\n \n4444444\n \n
Picture to example for escaped new lines:

Update series of numeric values in long string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have text column with following examplary data:
5,5,0.1;6,6,0.15;7,7,0.2;8,8,0.25;9,9,0.3;10,10,0.35;11,11,0.4;12,12,0.45;13,13,0.5;14,14,0.55;15,15,0.6;16,16,0.65;17,17,0.7;18,18,0.75;19,19,0.8;20,20,0.85;
I need to add some fixed value to each of numeric values (the one before semicolon)
so for example from:
5,5,0.1;6,6,0.15; I want add 0.15 so result would be:
5,5,0.25;6,6,0.3;
I guess I should try something with regexp_replace but I have no idea how to start here
The correct solution would be fix your broken data model and not store multiple, delimited values in a single column.
I wouldn't do this with a regex, but unnesting the elements of the string, adding the value to the third element, then aggregate everything back into the broken design:
update badly_designed_table
set denormalized_column =
(select string_agg(concat_ws(',', a, b, round(c + 0.15,2)), ';' order by idx)
from (
select split_part(val, ',', 1) as a,
split_part(val, ',', 2) as b,
split_part(val, ',', 3)::numeric as c,
idx
from unnest(string_to_array(bad_column, ';')) with ordinality as x(val,idx)
-- skip the "empty" element generated by the trailing ;
where nullif(val, '') is not null
) t)

Search an array of structs for a string variable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
consider:
const int CAP = 20;
struct bookType
{
string bookTitle = "EMPTY";
string ISBN = "EMPTY";
string author = "EMPTY";
string publisher = "EMPTY";
string dateAdded = "EMPTY";
int qty = 0;
double wholesale = 0.00;
double retail = 0.00;
};bookType book[CAP];
What I need to do here is hopefully simple, though I can't seem to get a straight answer on it. I want to search this array of structs (book[]) for a matching bookTitle. for instance, if I have a book named "Star Wars" I need to be able to search the array of structs by typing in "star" and finding a book, "Star Wars". I've been searching for hours, but all the solutions I've found don't seem to actually work.
I don't know the rest of you code so I'll try to give a generic answer.
It seems like you are looking for the find() function for string objects. The find function will return std::string::npos if it does not find anything.
So inside a loop, test:
Booktype[x].bookTitle.find("Star")!=std::string::npos
Change Star to the whatever you are searching for. If this condition is true then you haave a match.
Just a heads up, this is case sensitive so you might want create temporary variables and convert the titles and queries into lowercases and run the loop on them.
Hope this helps.

compare 2 arrays and get the values which are not matched :using perl map command or loops simply [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
arr1 = 1,2,3,4,5;
arr2 = 1,2,3;
want to compare and output as arr3=4,5;
Please help
thanks in advance
arry::utils error out, looks like some problem with the package, so that option is ruled out.
sub diff_array {
my ($a1, $a2) = #_;
my %h;
#h{#$a2} = ();
return grep !exists $h{$_}, #$a1;
}
my #arr1 = (1,2,3,4,5);
my #arr2 = (1,2,3);
my #arr3 = diff_array(\#arr1, \#arr2);

Different spellings of Chanukah Regex [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Hannuka, Chanukah, Hanukkah...Due to transliteration from another language and character set, there are many ways to spell the name of this holiday. How many legitimate spellings can you come up with?
Now, write a regular expression that will recognise all of them.
According to http://www.holidays.net/chanukah/spelling.htm, it can be spelled any of the following ways:
Chanuka
Chanukah
Chanukkah
Channukah
Hanukah
Hannukah
Hanukkah
Hanuka
Hanukka
Hanaka
Haneka
Hanika
Khanukkah
Here is my regex that matches all of them:
/(Ch|H|Kh)ann?[aeiu]kk?ah?/
Edit: Or this, without branches:
/[CHK]h?ann?[aeiu]kk?ah?/
Call me a sucker for readability.
In Python:
def find_hanukkah(s):
import re
spellings = ['hannukah', 'channukah', 'hanukkah'] # etc...
for m in re.finditer('|'.join(spellings), s, re.I):
print m.group()
find_hanukkah("Hannukah Channukah, Hanukkah")
Something like C?hann?uk?kah? matches most of the common cases. There also a bunch of weirder spellings C?hann?uk?kah?|Han[aei]ka|Khanukkah matches almost every spelling I could think of (that had at least half a million hits on google).
((Ch|H|X|Х|Kh|J)[aа](н|n{1,2})(у|ou|[auei])(к|k|q){1,2}[aа]h?)|(חנו?כה)
This regex is much more inclusive and covers all of the following options:
Channuka
Channukah
Channukka
Channukkah
Chanuka
Chanukah
Chanukah
Chanukka
Chanukkah
Chanuqa
Hanaka
Haneka
Hanika
Hannuka
Hannukah
Hannukka
Hannukkah
Hanoukka
Hanuka
Hanukah
Hanukka
Hanukkah
Januka
Khanukkah
Xanuka
Ханука
Ханука
חנוכה
חנכה
Try this:
/^[ck]?hann?ukk?ah?$/i
I think the only approved spellings in English are Hanukkah and Chanukh, so it's something like
/(Ch|H)anuk?kah/
Or maybe even better
/(Chanukah|Hanukkah)/
I like Triptych's answer, but i would take it one step forward... also in python:
def valid(spelling):
import re
regex_spelling = re.compile(r'^[cCkK]{0,1}han{1,2}uk{1,2}ah$')
valid = regex_spelling.match(spelling)
if valid:
print 'Valid spelling'
else:
print spelling, " is not a spelling for the word"
to use it:
valid("hanukkah")