i have create two text boxes and a command buttom. in text1 i put 01/06/2008. i want in text2 it will display 01-may-2008. but it is showing 06-jan-2008. please help...
Printable View
i have create two text boxes and a command buttom. in text1 i put 01/06/2008. i want in text2 it will display 01-may-2008. but it is showing 06-jan-2008. please help...
[ Split thread ]
Please do not post in old threads.
? So you put in Jan 6 and you want it to display May 1 ?Quote:
Originally Posted by sanjib294
If you are trying to modify the date then you need to give us a clue as to how you are trying to do it and what you are trying to accomplish.
btw May 1st would be written as 5/1/2008
use DateAdd() to get the correct date in text2
i want to insert date from text box. suppose i have put text1 as 01/05/2008. i want it should be posted like 01-may-2008. but it is showing 05-jan-2008. is there any option to do so. But whenever i am trying to insert sysdate it is showing correctly.........Pls help
try this
Code:Private Sub Command1_Click()
Text2.Text = Format(Text1.Text, "dd-MMM-yyyy")
End Sub
Well if I understand you correctly it sounds like you are either entering the date in the format of Day-Month-Year or your system is set to that format and you are entering Month-day-year. Either way the result is that the day and the month are reversed in your second field.Quote:
Originally Posted by sanjib294
If you display the date using the date statement how is it displayed? mm/dd/yyyy or dd/mm/yyyy? WHich ever it is you need to use this format when entering a date or change the settings to the format you want to use.
Use this:
Code:Dim splt() As String
splt = Split(Text1.Text, "/")
Text2.Text = Format(DateSerial(splt(2), splt(1), splt(0)), "dd-MMM-yyyy")
DateSerial() will return the date in system date format, hence no worry!
Riyaz
Seems like a waste of code.. If the user is entering a date in the first field then it is a simple matter of formatting it in the second field without need of calling anything other than the format.Quote:
Originally Posted by Shaikh.Riyaz.a
The thing is that the date has to be entered in the format that is expected just as in the code above if the date is not entered exactly as expected it will not return the correct results.
Not that it is a big deal but there is no need to write the code to parse out the first text box but rather a need to determine the correct format for entering the date.
Have your ever tried changing the regional settings for date?????Quote:
Originally Posted by WillAtwell
For exact output, there must be exact input and hence people writeQuote:
Originally Posted by WillAtwell
long validation codes for GUIs.
This takes a normal date format and converts it to serial number.
Dim intYear As Integer
Dim intMonth As Integer
Dim intDay As Integer
Dim lngSerial As Long
Dim strNewDate As String
Dim datDate As Date
datDate = CDate("01/05/2008")
intYear = Year(datDate)
intMonth = Month(datDate)
intDay = Day(datDate)
lngSerial = DateSerial(intYear, intMonth, intDay)
This converts a long integer representing a valid date into an accepted date format.
strNewDate = CDate(Format$(lngSerial, "dd-MMM-yyyy"))
Good luck.