Hi Meer25
We share the same destiny. I saw your profile and noticed your reputation is "under water". The same as mine on 'Stackoverflow' ;-)
Let me start with a consideration: over the years I noticed Microsoft did its best to confusing developers.
For example. when you are doing a web project and you double click over a button, to manage the 'click' event, the IDE writes for you the method for the event handler. That's good. What is wrong is that the method is server-side (run at server)
Why that is wrong?
The first big insight a new developer should have is that a web application is something that 'lives' in two different worlds with very different roles!
1) the so-called 'backend': the code that runs on a server, a machine that is waiting for an HTTP request and depending on the request returns an HTTP response (normally an HTML string: the web page)
2) The so-called 'frontend': the web page. Something that 'lives' into a browser waiting for an action from the user.
The frontend can be a project by itself: HTML pages without any server-side code (all my tips&tricks except logger for log4Net are front-end projects) In that case the only responsibility the server has is to provide all the files the page requests without processing anything.
Reading your question is absolutely clear you didn't have that insight!
1) your question should be managed client-side (another name for the frontend) using Javascript. (don't use any framework. start using javascript. And only when you will become confident with javascript start using the framework you prefer)
Please copy and paste this code and save it as "index.htm".
But: for this time, do not use any IDE like VSCode or Visual Studio. Just use any text editor like Notepad or Notepad++ or what else.
(The browser could be a perfect IDE, but now it is too early)
<!DOCTYPE html>
<html>
<title>Datediff</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<script>
function button_onclick(btn){
try{
debugger;
var now = new Date();
var input = window.prompt("Please enter a valid date in the format of 'dd-mm-yyyy'.", "01/01/2000");
var ticks = Date.parse(input);
var date = new Date(ticks);
var diff = daysDiff(date, now);
alert(diff);
}
catch(jse){
alert(jse.message);
}
}
function daysDiff(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000));
}
</script>
</head>
<body>
<button onclick="button_onclick(this)">Date diff</button>
</body>
</html>
It should run and it's a perfect "translation" of your VB.NET code.
Since you used the messageBox and InputBox it's clear your intention to interact with the user.
On a web page, you should manage the interaction with the user, client-side as much as you can.
In the case, you proposed you can!
Ask the server (the backend) only if you are forced (for example the user asked for data stored in a DB)
I hope this helps
cheers
Vincenzo