Share Blog

Saturday, July 28, 2018

Remove comma and add comma in string in c#


//remove comman and add comma
string department = "Support, Integration, Developer";
string dptment = "";
string[] dpt = department.Split(',');
for (int i = 0; i <= dpt.Length - 1; i++)
{
if (i == dpt.Length - 1)
{
dptment = dptment + dpt[i];
}
else
{
dptment = dptment + dpt[i] + ", ";
}
}
Console.WriteLine(dptment);
//remove comma and add without comman in list
List<string> lsttype = new List<string>();
string[] extracttype = department.Split(',');
for (int i = 0; i <= extracttype.Length - 1; i++)
{
lsttype.Add(extracttype[i]);
}
Console.WriteLine(lsttype.ToList());

Thursday, July 19, 2018

How to Generate OTP and Random Number in C#


private static string GenerateOTP()
{
Random generator = new Random();
String r = generator.Next(0, 1000000).ToString("D6");
if (r.Distinct().Count() == 1)
{
r = GenerateOTP();
}
return r;
}

Friday, July 06, 2018

How to find the days a login password was last changed in SQL Server


How to find the days a login password was last changed in SQL Server?

declare @days int
SELECT @days=DATEDIFF(day, Max(entrydate),GETDATE()) from users where id='1'
select @days as days

Compare date in c#,Asp.net

How to  compare Current system date to Input date?


Function Call

bool resp = CompareDate("06-07-2017");

Function Method

static bool CompareDate(string strDateTime)
{
DateTime dtFinaldate; string sDateTime;
try
{
dtFinaldate = Convert.ToDateTime(strDateTime);
if (dtFinaldate.Year > DateTime.Now.Year)
{
return true;

}
else if (dtFinaldate.Year == DateTime.Now.Year)
{
if (dtFinaldate.Month > DateTime.Now.Month)
{
return true;

}
else if (dtFinaldate.Month == DateTime.Now.Month)
{
if (dtFinaldate.Day >= DateTime.Now.Day)
{
return true;
}
}
}
return false;
}
catch (Exception e)
{
string[] sDate = strDateTime.Split('/');
sDateTime = sDate[1] + '/' + sDate[0] + '/' + sDate[2];
dtFinaldate = Convert.ToDateTime(sDateTime);
if (dtFinaldate.Year > DateTime.Now.Year)
{
return true;

}
else if (dtFinaldate.Year == DateTime.Now.Year)
{
if (dtFinaldate.Month > DateTime.Now.Month)
{
return true;

}
else if (dtFinaldate.Month == DateTime.Now.Month)
{
if (dtFinaldate.Day >= DateTime.Now.Day)
{
return true;
}
}
}
return false;
}
}

Wednesday, July 04, 2018

Creating a Countdown Timer in Java Script


<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
text-align: center;
font-size: 60px;
margin-top:0px;
}
</style>
</head>
<body>

<p id="demo"></p>

<script>
// Set the date we're counting down to
var seconds = 25;
interval = setInterval(function () {
seconds = seconds - 1;
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = seconds;
// If the count down is over, write some text
if (seconds < 0) {
clearInterval(interval);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>

</body>
</html>