Date Format
Page 1 of 18 Replies - 332 Views - Last Post: 05 October 2012 - 11:46 AM
#1
Date Format
Posted 04 October 2012 - 10:00 AM
I have this date. I want to strip the days, compare to current date, and ensure no more than 14 days are between the two dates.
What's the regex to strip the day value from this format. I will than convert it to a variable and do the same with the current date.
It's from a report.
Replies To: Date Format
#2
Re: Date Format
Posted 04 October 2012 - 10:07 AM
Edit: Sorry, I missed the part about regex.
But I still stand behind the TimeSpan structure to get the difference between 2 dates as a solution
This post has been edited by CharlieMay: 04 October 2012 - 10:17 AM
#3
Re: Date Format
Posted 04 October 2012 - 11:09 AM
Also, I'm curious about this line:
Quote
What do you mean by stripping days? Do you mean you want to extract them? Or just remove them from the date?
If all you're looking for is the number of days between two dates, you're better off using the built in classes:
var date = DateTime.Parse("9/18/2012 2:40:44 PM");
var now = DateTime.Now;
//find difference
var difference = now - date;
Console.WriteLine("There are {0:#.##} days between {1} and {2}.", difference.TotalDays, date, now);
If by "strip" you mean remove that information from the date, that's pretty easy too:
var date = DateTime.Parse("9/18/2012 2:40:44 PM");
var stripped = new DateTime(date.Year, date.Month, 1, date.Hour, date.Minute, date.Second, date.Millisecond);
Console.WriteLine("{0,-10}{1}{2}{3,-10}{4}", "Date:", date, Environment.NewLine, "Stripped:", stripped);
#4
Re: Date Format
Posted 04 October 2012 - 11:23 AM
The problem with this however is what happens if the first date is September 30th 2012 and todays date is October 4th 2012. That would give you 30 - 4 = 26 when actually only 4 days have passed.
This is why you should use the entire date as Curtis Rutland and I pointed out.
This post has been edited by CharlieMay: 04 October 2012 - 11:23 AM
#5
Re: Date Format
Posted 04 October 2012 - 04:15 PM
Yes, that's the very problem I sort of ran into with the next month issue Charlie. I like this technique. I have to make sure that any report older than 14 days isn't visible on the system. So if I use this:
var difference = now - date;
I should be fine, right?
Thank you Curtis.
#6
Re: Date Format
Posted 04 October 2012 - 04:21 PM
#7
Re: Date Format
Posted 05 October 2012 - 08:53 AM
int indexx = -11;
int indexxTmp = 0;
int offSet = 11;
int offSet2 = 8;
int maxLoop = 0;
int multi = indexx + offSet2 - 1;
string found = string.Empty;
string[] textStrArr = {"Created", "Incomplete", "Complete", "Cancelled Without QA"};
string[] textStrArr2 = {};
string[] textStrArr3 = {};
string tmpStr = string.Empty;
string differenceStr = string.Empty;
string differenceTotStr;
int differenceTot = 0;
var grid = repo.portal.buttons.Column_Headings.rgMasterTable;
var editQA = repo.portal.Order_Details.EditQA;
var viewQA = repo.portal.Order_Details.View;
var date = System.DateTime.Parse("9/18/2012 2:45:44 PM");
var now = System.DateTime.Now;
var difference = now - date;
//System.DateTime = now - date;
IList<TrTag> myList = grid.FindDescendants<TrTag>();
IList<TdTag> myList2 = grid.FindDescendants<TdTag>();
differenceStr = difference.ToString();
differenceTot = Convert.ToInt32(difference.TotalDays);
differenceTotStr = differenceTot.ToString();
// foreach(Ranorex.TdTag tag in myList2 )
{
// myList2[1].MoveTo();
// myList2[1].PerformClick();
maxLoop = (int)(myList2.Count / (offSet));
for (int j = 0; j < maxLoop - 1; j++)
{
// indexxTmp = indexx / maxLoop;
indexx += offSet;
myList2[indexx].MoveTo();
tmpStr = myList2[indexx].InnerText;
if(tmpStr == textStrArr[0].ToString())
{
myList2[8].MoveTo();
myList2[8].GetInnerHtml();
now = System.DateTime.Parse(myList2[8].GetInnerHtml());
Console.WriteLine("There are {0:#.##} days between {1} and {2}.", difference.TotalDays, date, now);
Report.Info(differenceStr);
Report.Info(differenceTotStr);
if(difference.TotalDays > 14)
{
Report.Failure("fail");
}
}
Report.Info(tmpStr);
}
I tried doing traversing through with this type of logic:
myList2[indexx + offSet2].MoveTo(); myList2[indexx + offSet2].GetInnerHtml(); now = System.DateTime.Parse(myList2[multi].GetInnerHtml());
#8
Re: Date Format
Posted 05 October 2012 - 11:44 AM
public void DateFinalFirstRow()
{
int indexx = -11;
int indexxTmp = 0;
int offSet = 11;
int offSet2 = 8;
int maxLoop = 0;
int multi = indexx + offSet2 - 1;
string found = string.Empty;
string[] textStrArr = {"Created", "Incomplete", "Complete", "Cancelled Without QA"};
string[] textStrArr2 = {};
string[] textStrArr3 = {};
string tmpStr = string.Empty;
string differenceStr = string.Empty;
string differenceTotStr;
string dateStr;
int differenceTot = 0;
var grid = repo.portal.buttons.Column_Headings.rgMasterTable;
//var editQA = repo.portal.Order_Details.EditQA;
//var viewQA = repo.portal.Order_Details.View;
var date = System.DateTime.Parse("9/18/2012 2:45:44 PM");
var now = System.DateTime.Now;
var difference = now - date;
//Ranorex.DateTime = now - date;
IList<TrTag> myList = grid.FindDescendants<Ranorex.TrTag>();
IList<TdTag> myList2 = grid.FindDescendants<Ranorex.TdTag>();
// foreach(TdTag tag in myList2 )
{
// myList2[1].MoveTo();
// myList2[1].PerformClick();
maxLoop = (int)(myList2.Count / (offSet));
for (int j = 0; j < maxLoop - 1; j++)
{
// indexxTmp = indexx / maxLoop;
indexx += offSet;
myList2[indexx].MoveTo();
tmpStr = myList2[indexx].InnerText;
if(tmpStr == textStrArr[2].ToString())
{
//myList2[indexx + 8].MoveTo();
dateStr = myList2[indexx + 8].InnerText;
Report.Info(dateStr);
date = System.DateTime.Parse(dateStr);
difference = now - date;
differenceStr = difference.ToString();
differenceTot = Convert.ToInt32(difference.TotalDays);
differenceTotStr = differenceTot.ToString();
Console.WriteLine("There are {0:#.##} days between {1} and {2}.", difference.TotalDays, date, now);
Report.Info(differenceStr);
Report.Info(differenceTotStr);
if(difference.TotalDays > 14)
{
Report.Failure("fail. More than 14 days have passed and a completed order still remains");
}
if(difference.TotalDays <= 14)
{
Report.Success("The items are less than 14 days old. Matching the requirement");
}
}
Report.Info(tmpStr);
}
This post has been edited by Curtis Rutland: 05 October 2012 - 11:45 AM
#9
Re: Date Format
Posted 05 October 2012 - 11:46 AM
|
|

New Topic/Question
Reply



MultiQuote




|