show / hide menu

How to get date details from date time field

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.

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.

Figure 2

Step 3 : Write the following rule on ‘Get Date Details’ button  as the trigger.

Figure 3

Rules :

  • hdnDate.Value=dtpDate.Value

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’.

  • txtDay.Value=SubString(0,GetIndex(hdnDate.Value,”-“,0),dtpDate.Value)

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.

  • hdnDate.Value=StringReplace(hdnDate.Value,txtDay.Value+”-“,””)

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.

  • txtMonth.Value=SubString(0,GetIndex(hdnDate.Value,”-“,0),hdnDate.Value)
    We can get the Month from this rule.
  • hdnDate.Value=StringReplace(hdnDate.Value,txtMonth.Value+”-“,””)

This rule will remove the Month value from the ‘hdnDate’  control.

  • txtYear.Value=SubString(0,GetIndex(hdnDate.Value,” “,0),hdnDate.Value)

We can get the Year from this rule.

  • txtTime.Value=StringReplace(hdnDate.Value,txtYear.Value+” “,””)

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.

Figure 4

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.

Figure 5

Step 3 : Write the following rule on ‘Get Date Details’ button  as the trigger.

Figure 6

Rules :

  • txtDay.Value=GetDay(dtpDate.Value)

We can get the day in the ‘txtDay’ control.

  • txtMonth.Value=GetMonth(dtpDate.Value)

We can get the month in the ‘txtMonth’ control.

  • txtYear.Value=GetYear(dtpDate.Value)

We can get the year in the ‘txtYear’ control.

Preview :

Figure 4

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 .