Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

formating date for combo box

I have this code

cboPayPeriod.DataSource = myDS.Tables(1)
cboPayPeriod.DisplayMember = Format("BeginDate", "mm/dd/yy")

of course not getting the format results I was looking for.  Without format I receive the dates with the time as well. 04/29/04 12:00:00AM.  I only want the date.  How can I format in the combo box.

thanks

Avatar of Mani Pazhana
Mani Pazhana
Flag of United States of America image

Try This:

Dim dtNow As DateTime = DateTime.Now  'Your date with time before formatting

strdate = dtNow.ToShortDateString  'Your date after formatting (mm/dd/yyyy).


Thanks



Avatar of mgmhicks
mgmhicks

ASKER

Yea that probably works put how to I get that in the line


cbopayperiod.displaymember = "the data in the format I want"


cboPayPeriod.DataSource = myDS.Tables(1)

'If your BeginDate is  of type DateTime

'Then you can use this code:

cboPayPeriod.DisplayMember = BeginDate.ToShortDateString  

begindate has to be in quotes or I get a error.

you can use this:

Dim strdate  as string

Dim dtNow As DateTime = DateTime.Now

        MsgBox(dtNow)  'Before Formatting

        strdate = String.Format("{0:d}", dtNow)

        MsgBox(strdate)  'After Formatting


Please Note : you have to pass parameter of type DateTime.

It will work fine.
Avatar of Bob Learned
What is the data source (Access, SQL Server, Oracle)?  There are functions on the DBMS side that can format the data as specified, but they differ depending on the system.

Bob
the database is sql
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

r you using any stored procedure to get data in your scenario.


if yes show your stored proc code. we can take a look.

Also your front end code. It will help to solve your problem