1).please write an example of getting the smallest value than can sub divde"128"2).please write an example of convertinfg string value "31/12/2000" to date time and at the same time change its format "mm/dd/yy"3). please write an example of reurnning a date that is the last day of the month.8 months from todays date4).please write an example of formatting a variable of fromatting a variable in doubble data type with value "1800000.7" to "$1,8000.000.70"

Showing Answers 1 - 4 of 4 Answers

Topgun

  • Sep 11th, 2006
 

int number = 128;

int i = 1;

While(i < (number/2))

{

if ( number % i == 0)

       return number;

     i++;

}

  Was this answer useful?  Yes

prasad

  • Sep 11th, 2006
 

Q2)

System.DateTime dt = System.DateTime.Now.AddMonths(8);

int month = dt.Month;

int i = 1;

while( month == dt.AddDays(i).Month)

{

i+= 1;

}

System.DateTime lastDayOfMonth = dt.AddDays(i-1);

System.DateTime 8thLastDayOfMonth = dt.AddDays(i-1);

  Was this answer useful?  Yes

R.Ravi Kumar

  • Jan 2nd, 2007
 

Q2) Actualy the date formate will be "mm/dd/yyyy",if we changed the formate to assaigned into date variable it will show formate error.

date variable will accept some foramate as per my knowledge.

--> If we assaigned "12/2000" formate,date variable will take "12/1/2000" formate.

ex:

dim _date as date="12/2000"

msgbox(_date)  //output is 12/1/2000 by default it will take 1 day

--> If we assaigned "12/2000/31" fomate ,date variable will take "12/31/2000" formate

dim _date as date="12/2000/31"

msgbox(_date) //output is 12/31/200

In Below example: we are removeing "31/" from "31/12/2000" formate and added that at lost of the word like : 12/2000/31, and finally i assaigned to date variable then as i said above that formate will be 12/31/2000 formte.

--------------

Dim _strdate_string As String = "31/12/2000" 

_strdate_string = Mid(_strdate_string, _strdate_string.IndexOfAny("/") + 2, _strdate_string.Length) + "/" + Mid(_strdate_string, 1, _strdate_string.IndexOfAny("/"))

Dim _strdate As Date = Convert.ToDateTime(_strdate_string)

MsgBox(_strdate)  //out put "12/31/2000"

  Was this answer useful?  Yes

R.Ravi Kumar

  • Jan 2nd, 2007
 

Q3)

If Date.Now.Month + 8 > 12 Then

MsgBox(Date.DaysInMonth(CType(Date.Now.Year + 1, Integer), Date.Now.Month + 8 - 12))

Else

MsgBox(CType(Date.DaysInMonth(Date.Now.Year, Date.Now.Month + 8), String))

End If

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions