Robotuim setDatePicker() picking current day's date only - robotium

This is my code;
solo.clickOnEditText(0);
solo.setDatePicker(null, 2014, 8, 8);
solo.clickOnText("Done");
No matter what parameters I give, the date picker keeps returning the current days date. Does anybody have any idea how I can go about fixing this? Thank you in advance.

You should not pass null (number or object)
solo.setDatePicker(0, 2014, 8, 8); // the first param is an index
or first get DatePicker object:
DatePicker datePicker = solo.getView(DatePicker.class, 0); // the second param is an index
or by id:
DatePicker datePicker = solo.getView(String/int id)
then set date for the picker:
solo.setDatePicker(datePicker, 2014, 8, 8);

Related

Default date in datetimepicker in visual studio

If the user selects the date in the DateTimePicker, it only picks up the date, which is what I need. However, if the user doesn't select any date and leaves the DateTimePicker as today's date, it shows date + time. The data is stored in an Access database. I want to store the date only in the Access store when the user leaves the DateTimePicker to today's date (without changing any date).
Me.DateTimePicker1.CustomFormat = "dd-MM-yyyy"
Me.DateTimePicker1.DataBindings.Add(New System.Windows.Forms.Binding("Value", Me.OrderdetailsBindingSource, "OrderDate", True))
Me.DateTimePicker1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.OrderdetailsBindingSource, "OrderDate", True))
Me.DateTimePicker1.Font = New System.Drawing.Font("Tahoma", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.DateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom
Me.DateTimePicker1.Location = New System.Drawing.Point(158, 39)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(294, 28)
Me.DateTimePicker1.TabIndex = 2
Me.DateTimePicker1.Value = New Date(2019, 6, 18, 0, 0, 0, 0)
Access does not have a short date format such as SQL Server. See this link for lists of data types.
Access:
Date/Time, Use for dates and times, 8 bytes
SQL Server:
datetime, From January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds, 8 bytes
date, Store a date only. From January 1, 0001 to December 31, 9999, 3 bytes
So Access only has one date/time type which must be able to store time, which has the same number of bytes as SQL Server datetime. The date without a timestamp you see is actually 12 AM. This is what you are doing when you set the date/time on your DateTimePicker Me.DateTimePicker1.Value = New Date(2019, 6, 18, 0, 0, 0, 0). This is incidentally your best solution, to set the DateTimePicker to today's date (just the date portion using the DateTime.Date property I menioned).
To solve your problem, do this in Form_Load:
Me.DateTimePicker1.Value = Now.Date ' this makes it today at 12 AM
If you want to better understand what is going on, check out the value of your DateTimePicker at any time with this, to see that there is always a time in it, even if it's 12 AM:
MessageBox.Show($"{DateTimePicker1.Value:yyyy-MM-dd HH:mm:ss}")
And run this query on your database to see that there is also always a time in an Access Date/Time field, and that Access automatically hides the time when it is 12 AM:
select
orderdate
, format(orderdate, 'General Date') as GeneralDate
, format(orderdate, 'Short Time') as ShortTime
, format(orderdate, 'Medium Time') as MediumTime
, format(orderdate, 'Long Time') as LongTime
, format(orderdate, 'Short Date') as ShortDate
, format(orderdate, 'Medium Date') as MediumDate
, format(orderdate, 'Long Date') as LongDate
from orderdetails
Sorry, if I am not able to answer you perfectly in vb.net
i will give you an Answer in vb (how i mean it is correct)
and in correct c#
i understood that you want the code to save values in the database, if the date of the DateTimePicker is set today.
c#
if(dateTimePicker1.Value.Date == DateTime.Today)
{
//insert your code here
}
vb.net
if dateTimePicker1.Value.Date == DateTime.Today
//Code here
end if
this if asks, if the picket Date of the DateTime is the same Date as today
if you just want to save the whole value of the date in the DataBase if the picked date is today so like: "25.06.2019 17:25" then you will have a problem.
If you save it as String you could format it:
dateTimePicker1.Value.ToString("HH:mm dd.MM.yyyy")
or
dateTimePicker1.Value.ToString("HH:mm")
so put the second in the "else" braket.
if you only need Date or time, you can format it like the above.
(sorry i am not sure if i understood your question right, so if it doesn't help you, just comment. I will answer)

How to calculate time difference between two times in vb

I need to calculate time difference between two time
The shift Start time is 04:30:Pm to 12:30AM
The Employee IN time is 08:30 AM then it shows the error message time expired
What I have tried:
dtShifTime = Convert.ToDateTime("16:30").ToString("HH:mm")
Dim dtEntryTime As DateTime = Convert.ToDateTime("08:30").ToString("HH:mm")
If lblStartTime.Text <> "" And (dtLateTime < dtEntryTime) Then
MBox("Time Expired")
End IF
By calling ToString you convert the DateTime object into a String. And then you save it into a DateTime variable.
I don't know what you're trying to do, but to get the difference between two times you just subtract them.
Dim dtStart As DateTime = new DateTime(year:= 1, month := 1, day:= 1, hour:= 8, minute:= 30, second := 0)
Dim dtEnd As DateTime = new DateTime(year:= 1, month := 1, day:= 1, hour:= 20, minute:= 0, second := 0)
Dim tsDiff As TimeSpan = dtEnd - dtStart
Console.WriteLine(tsDiff.ToString())
I recommend you read the documentation for what you're trying to use.
DateTime and TimeSpan.
Instead of the constructor you can parse with DateTime.Parse(), ParseExact or TryParse if you definitely need to use a string as an input, which you should avoid if possible.
Aside from that you should do some basic searching and researching. For example this comes up as the first hit: Get time difference between two timespan in vb.net when searching "time difference vb.net"

dateTimePicker only returning today's date in vb express

I have a vb net project where I have multiple forms each outfitted with a datetimepicker.
For some reason, my datetimepicker in any form isn't returning the selected value i pick but rather, it only returns the current date. I'm ultimately trying to get a string out of the datetimepicker in the format of "YYYYMMDD" (i.e Jan 12, 2016 = "20160112") using a private function below:
for example I picked on my datetimepicker Jan 12, 2016. However the function computes y = 2016, m = 6, and d = 9 as today is Jul 9, 2016.
Private Function getdatefromdatepicker() As String
Dim y, m, d As String
y = Me.DateTimePicker.Value.Year.ToString()
m = Me.DateTimePicker.Value.Month.ToString()
d = Me.DateTimePicker.Value.Day.ToString()
Return y & m & d
End Function
I'm lost with this. If someone could solve how to extract the selected date and get the string format I desire, that would be great. Thanks in Advance.
The DateTimePicker exposes the DateTime value through the Value property. You can then use use Day, Month and Year to get the values like so:
int day = DateTimePicker.Value.Day;
int month = DateTimePicker.Value.Month;
int year = DateTimePicker.Value.Year;

Mongodb update datetime field

I have written the following code to update a datetime field with today's datetime:
User.update( {'email': email } , {'resetpwddateExpire' : new Date() })
The date part is updating correctly, but the time part is not. For example:
if resetpwddateExpire starts as 2/14/2014 8:08:52 AM
after the update, resetpwddateExpire is now 2/7/2014 9:08:52 AM
but it should be 2/7/2014 3:08:52 PM
I assume you are using Mongoose. It seems to me that when the document was created, the resetpwddateExpire field was set to sometime in future. And when you update it, it becomes today's date which is 7th Feb 2014.
Perhaps using $set operator would help.
var oneWeek = 7 * 24 * 60 * 60 * 1000;
User.update( {'email': email } , {'$set': {'resetpwddateExpire' : Date.now() + oneWeek}}, function(...){});

DateTime question in VB.NET

Ok, so I need to find the date of Monday this week programmatically.
For example, for this week Monday was on the 9th, so the date I need is: 09/11/2009
And when we roll over to next week it needs to calculate: 16/11/2009
I have tried doing this myself but I can't see how to do the arithmetic, thank you.
C#:
date.AddDays(1 - (date.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)date.DayOfWeek));
VB.NET:
date.AddDays(1 - IIf((date.DayOfWeek = DayOfWeek.Sunday), 7, date.DayOfWeek))
Dim thisMonday As Date = Now.AddDays((Now.DayOfWeek - 1) * -1).Date
If today is a Sunday it gives the following Monday otherwise, gives the Monday this week.
Return givenDate.AddDays(1 - CType(IIf((givenDate.DayOfWeek = DayOfWeek.Sunday), 7, givenDate.DayOfWeek), Double))
If givenDate is a Sunday, counts back to the preceding Monday. Includes a CType to cast the IIf result to a Double to work with Option Strict On.