How to get date details from date time field
There are two methods for getting date details (day,month,year,time) from the date time field.
1) Using SubString and StringReplace function
Step 1 : Create a form with DateTimePicker control, 4 Text-boxes ,1 hidden control ,1 button as shown in the figure 1.
Step 2 : Click on the DateTimePicker control to get its properties . Select the Date Format for example here we selected ‘dd-mm-yyyy’ format. Also check the Time picker check-box to show the time.
Step 3 : Write the following rule on ‘Get Date Details’ button as the trigger.
Rules :
The value in DateTimePicker control is assigned to the hidden control ‘hdnDate’ . for example hdnDate will get a value like ‘ 15-03-2016 12:00 AM’.
By using ‘SubString’ function the day (i.e string before hyphen) is taken and stored in ‘txtDay’ control. By using ‘GetIndex’ function we can get the index of hyphen in the date.
After getting value of day in ‘txtDay’ ,the value of day must be removed from ‘hdnDate’ control by using ‘StringReplace’ function to replace the day with space.
This rule will remove the Month value from the ‘hdnDate’ control.
We can get the Year from this rule.
We can get the time in ‘txtTime’ control .
2) Using GetDay and GetMonth and GetYear function
Step 1 : Create a form with DateTimePicker control, 4 Text-boxes ,1 hidden control ,1 button as shown in the figure 1.
Step 2 : Click on the DateTimePicker control to get its properties . Select the Date Format for example here we selected ‘dd-mm-yyyy’ format. Also check the Time picker check-box to show the time.
Step 3 : Write the following rule on ‘Get Date Details’ button as the trigger.
Rules :
We can get the day in the ‘txtDay’ control.
We can get the month in the ‘txtMonth’ control.
We can get the year in the ‘txtYear’ control.
Preview :
Enter the date and time and then click on ‘Get Date Details’ button. Day, Month,Year, Time will be shown as result in the respective text-boxes as shown in the Figure 4 .