Saturday, May 14, 2011

Date and Time manipulation

Hi Folks,

Recently I was working with dates and times inside my application, and it took a long time since I figured out how to deal with dates and time.

The senario is that I have an applciation where I store DateTime values in a SQL column, and I created a Form to filter the records based on From Date and To Date.

Here is the Table structure:


And here is sample of the data inside the table:


As you can see that it consists of 2 parts, Date and Time.

Then I created the following form to filter the date column between to dates:


And to filter the dates you can use the following code:

If FromDateTextBox.Text <> "" And ToDateTextBox.Text <> "" Then
           Dim fd As DateTime = DateTime.Parse(LTrim(RTrim(FromDateTextBox.Text)))
           Dim td As DateTime = DateTime.Parse(LTrim(RTrim(ToDateTextBox.Text)))
           criteria += " AND (Convert(varchar(20), CreatedOn, 101) BETWEEN '" & fd & "'" & " And '" & td & "')"

End If


The explination:
Convert(varchar(20), CreatedOn, 101 will take the Date only part from the CreatedBy column amdf then we can compare it.

Another note that you need to put the variables values between singlr brackets 'value'.

Happy programming!
Saed

Thursday, May 5, 2011

Zoom It! Tool in action!

Hi Folks,

This time I will not be talking about programming though it's a very usefull tool for everybody, I will be talking about using Zoom It! tool.

Where you can Zoom In to the screen while presenting your software code, interface or even in any of your presentations and fun stuff.

To download the tool, you just login to Microsoft Windows Sysinternals and search for Zoom It!, here is a link to download.

How to use it:
1- You need to run the Zoom It program.
2- To Zoom in: press Ctrl + 1
3- To Draw on the screen: while in the zome mode, click on the screen, then you can Draw on the screen.
4- To Type on the screen: while in the zoom mode, press the letter "T", then move the mouse over and start typing.

Below is a sample video I have recorded to show you Zoom It in action.

Happy presentations!
Saed

Monday, May 2, 2011

Validate Current Time in InfoPath

Hi Folks,

Recently I as looking for a way to calculate the current time in InfoPath to be used in the default value field or the validation, I've been googling alot but I couldn't find a solution untill I got it working!

The senario I will be explaining here is I need a field to enter a time, and I want to validate that the time entered should be at least after 1 hour of the current time.

The concept is to get the current time, then add 3600 (60 sec X 60 min) second to it, so the time entered by the user should be Less Than the current time added 3600 seconds (1hour).

The steps goes:
1- In InfoPath, add a Text Box.
2- Open the Text Box Properties window.
3- Change the Data Type to "Time".
4- Click on the Format button to chage the Time Format to "9:46 AM".


5- Click OK once, then click on Data Validation button.
6- Then click on Add button in Data validation screen.
7- Choose (is less than), and choose (Use a formula) from the drop down box, to create the formula.


8- Then Insert Formula dialog box will appear.
9- Then click on Insert Function button, the Insert function dialog box will appear.
10- Chose Date and Time, and chose "addSeconds" Function, and click OK button.


11- Then you need to change the formaula as follows:


12- The Formual is: addSeconds(substring-after(now(), "T"), 3600)

This formual will take the time part of NOW() function, then it will add 1 hour (60 sec X 60 min), so the validation will be:

If the field entered is Less Than the Current time + 1 hour, then it will pop up an error, the time should be at least after 1 hour of the current time.

13- Click on OK button, then type the Screen Tip, Message and check the Show dialog box messages ...


14- Click on OK button 3 times.

15- Preview the form, and try to type a time after 30 min after your PC current time, it will give you the error as follows:



That's it!

Happy programming!
Saed