Click here to Skip to main content
16,012,611 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to save datetime into access with format "dd/MM/yyyy hh:mm:ss"?
i'm try using this format but miss with day and month ..
in my access db using format " dd/mm/yyyy hh:nn:ss "
so i use format like this and haven't miss ..

What I have tried:

dim actdate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss")

and using save method :
cmd.parameters.Add(New OleDbParameter("letdate", CType(actdate, Date)))
Posted
Updated 7-Sep-17 20:06pm
v2
Comments
PIEBALDconsult 8-Sep-17 0:41am    
Do not use string for dates. Dates do not have a format until you display them.
Khabibb Mubarakk 8-Sep-17 0:57am    
just like this?
 actdate = DateTime.Now 
PIEBALDconsult 8-Sep-17 8:24am    
Yes, better.
Khabibb Mubarakk 8-Sep-17 10:17am    
mismatch bro

1 solution

Like this:
VB
Dim actDate as DateTime = DateTime.Now
cmd.parameters.AddWithValue("letdate", sctDate)
 
Share this answer
 
Comments
Khabibb Mubarakk 8-Sep-17 6:21am    
it's make mismacth criteria !
OriginalGriff 8-Sep-17 6:46am    
Then you are trying to store dates as strings, which is a very bad idea - it always comes back to bite you later.
Change your DB so you store items in appropriate datatypes: integers, in INT, floating point in FLOAT, money in DECIMAL, and Dates in DATE, DATETIME, or DATETIME2 columns. Only string based data belongs in VARCHAR or NVARCHAR columns.
Khabibb Mubarakk 8-Sep-17 7:43am    
i won't to store date as string..
exactly i set db in appropriate datatype.
but when i try save using date.now or datetime.now then i got message mismatch criteria..
OriginalGriff 8-Sep-17 8:18am    
Show the exact code you are using, and your table design.
Khabibb Mubarakk 8-Sep-17 10:29am    
this exact my code as you want
letdate on access database using datetime datatype..
call koneksi()
sql = "insert into cube([no],[letdate])" & " "values(?,?)"
cmd = New OleDbCommand(sql, conn)
dim actdate as datetime = DateTime.Now
With cmd.Parameters
    .Add(New OleDbParameter("@no", CType(serno.Text, Integer)))        
    .Add(New OleDbParameter("@letdate", CType(actdate, Date)))
End With
cmd.ExecuteNonQuery()
cmd.Dispose()
conn.Close() 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900