473,503 Members | 12,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting a date and time string to date/time format

219 New Member
I've got two fields in my database. There are date and time fields, but they are both type text. I need to concatenate these fields together and convert them to a date/time data type. I've tried a few things in my query, but am not having any luck. How should I go about doing this?
Jan 18 '08 #1
6 31920
missinglinq
3,532 Recognized Expert Specialist
In a blank field in your query

Expand|Select|Wrap|Line Numbers
  1. CombinedDateTime: [YourDateField] & " " & [YourTimeField]
  2.  
Then, in a form or report, use CombinedDateTime as you would any other field. You don't say what you'll be using it for, but the field will work in Access date functions like DateAdd() and DateDiff() without doing anything else. If you should have trouble with it in your particular situation, you could coerce it to a Date datatype by using CDate(CombinedDateTime)

Linq ;0)>
Jan 18 '08 #2
dmorand
219 New Member
In a blank field in your query

Expand|Select|Wrap|Line Numbers
  1. CombinedDateTime: [YourDateField] & " " & [YourTimeField]
  2.  
Then, in a form or report, use CombinedDateTime as you would any other field. You don't say what you'll be using it for, but the field will work in Access date functions like DateAdd() and DateDiff() without doing anything else. If you should have trouble with it in your particular situation, you could coerce it to a Date datatype by using CDate(CombinedDateTime)

Linq ;0)>
CDate will only convert a string to a date. It won't do a time field as well will it?
Jan 21 '08 #3
missinglinq
3,532 Recognized Expert Specialist
Not sure exactly what you're trying to do, or exactly what you mean by a "time" field, but in point of fact, there is no such thing in Access as a "Time" field! All fields defined in the underlying table to a hold Date and/or Time values are actually Date/Time datatype.

If only the "date" part is entered, Access completes the field by adding 00:00:00 for hours/minutes/seconds. The opposite is true as well. If a "time" is entered, Access adds the default date of 12/30/1899 to it.

Access internally stores Date/Times as Doubles. 1/21/2008 is actually stored as 39468, which is the number of days since the previously mentioned 12/30/1899. The time part is stored as the part of a day, so that 1/21/2008 12:00:00 (noon) would be stored as 39468.5.

As I said before, for most functions Access will accept a "date" if it looks like a date, and a "time" if it looks like a time. CDate() will coerce any expression into a date that can be reasonably be interrpreted as a date.

CDate("1/21/2008")
will return 1/21/2008, even though "1/21/2008" is a string. CDate(39468) will also return 1/21/2008 a date because, in Access' eyes, the expression 39468 can be interpreted as a date.

When do you use CDate()? Don't really know; I've never had to. Perhaps in SQL which is not as forgiving as VBA.

Linq ;0)>
Jan 21 '08 #4
dmorand
219 New Member
I found out that the issue is the time I'm trying to piece together with the date is in military time, and not a 12 hour format (AM/PM). I am hoping there's an easy way to go from military to 12 hour.
Jan 21 '08 #5
missinglinq
3,532 Recognized Expert Specialist
You do that with formatting. If the value in YourDateField is

12/31/2007 13:45:00


then

Format(YourDateField, "mm/dd/yyyy hh:hh:ss am/pm")

will return

12/31/2007 1:45:00 pm

Linq ;0)>
Jan 21 '08 #6
dmorand
219 New Member
Thanks, let me give that a try
Jan 21 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11646
by: dan glenn | last post by:
Say, I want to set a cookie and have it expire an hour after it's set. It's looking like this is only possible for browsers which are in the same time zone as my server?? In other words, if I...
0
1816
by: Brian | last post by:
I want to convert the time string from the if-modified-since header into a unix time stamp, so I looked at the strtotime() function. The PHP manual on that function makes reference to a GNU manual...
5
16281
by: goochey | last post by:
I'm trying to convert a Julian Date (Format "4365") into an actual calendar date in Visual Basic, can anyone help me out with this.
7
1595
by: Geoff Jones | last post by:
Hi I've just found something very strange when using Date types within string. Consider the following: Dim myDate = DateValueRow("The Date") ' myDate is a date taken from a DataTable '...
1
8392
by: Matt Gyton | last post by:
Can anyone help me, I need a way to convert a date in DD/MM/YYYY format (the time is also present but that's not too important in this case....) into a UTC integer using ASP/VBScript....for...
2
4703
by: stainless | last post by:
I know this is probably simple but I cannot find a method of converting a date string into a format that matches the DatePicker format in C# eg string "20080131" converted to "31 January 2008" ...
19
20214
by: robtyketto | last post by:
Greetings, I have the following code below which allows the date to be added via a JDBC connection as a STRING. The value of dateString is inserted into the MS ACCESS database. What is the...
8
3049
by: Tony B | last post by:
I have a string in a existing php script which is in the form "dd/mm/yyyy" and I need to convert it into a suitable format for mysql which is "yyyy-mm-dd" Is there a neat way of doing this in php ?
1
1708
by: Thierry Lam | last post by:
I have a python time string which has the following value: 1225137896 The above corresponds to 2008/10/27 16:04:56 What can I use to convert 1225137896 to a more readable date, time format?
0
1421
by: dougancil | last post by:
I have the following code: Imports System.Data.SqlClient Public Class Main Protected WithEvents DataGridView1 As DataGridView Dim instForm2 As New Exceptions Private Sub...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.