create a Date & Time value from separate date & time text strings

I have a spreadsheet with a column of numeric values representing dates, e.g. 01-01-23, and a second column representing times, e.g. 09-15. I want to end up with a third column with true Numbers Date & Time entries, e.g. 01/01/2023 09:15, so they can be sorted properly.

I can extract the various values from the date and time columns but the DATEVALUE function just gives me the date with the time set to zero, e.g. 01/01/2023 00:00. I guess I'm missing something easy but I can't see what it is.

Posted on Mar 6, 2025 8:57 AM

Reply
11 replies

Mar 6, 2025 11:21 AM in response to rgb99

Simple. Your calculation is wrong.


Looking at the cell Table 1::A2, the formula can be broken down into components:


DATE() + " " + TIME()


This creates a TEXT object that might look like a date, but it's really just text, which is why you can't use date calculations on it.


Instead, this function needs to combine a DATE() plus a number of hours/minutes/seconds using the DURATION() function:


=DATE(RIGHT(),LEFT(),MID()) + DURATION(0,0,LEFT(Date-Time::B2,2),RIGHT(Date-Time::B2,2),0,0)


(RIGHT/LEFT/MID parameters omitted for clarity)


This adds the hours/minutes to the DATE() calculated from the date field.


What you end up with is a valid DateTime field and can use the normal Format -> Cell -> Date & Time options to display whichever date/time components you want.

Mar 6, 2025 12:11 PM in response to bob264

> Question tho: I built the tables using the same values and saw the same results with the dates formatted as dates but Numbers clearly saw it as text. That puzzles me. Can you help with that?


Do you mean in your original Table 1::A2 cell?


The date is formatted correctly because it is a date - or at least it was.


Let's take a simplified version:


=DATE(2025,1,1) & " " & TIME(9,50,0)


The DATE() function takes a value for year, month and day, and returns a valid date object. By default, based on your system internationalization settings, this will look like 1/1/2025 (the 00:00:00 is not relevant for this discussion)


Similarly, the TIME() function will take a value for hours, minutes and seconds, and return a valid time object such as 9:50:00 am


The issue is that you combined that DATE() field with a string ( & " " & ).


At this point, the DATE() field has no option but to be converted to a text object since you're appending a space to it. That's why the date part looks right, but it is treated as a text object as far as Numbers is concerned, and you lose any date-related functionality.


You then further add the time object to the end of that string and that forces the time object to lose any concentration of datetime functionality... it's just another string of characters.


"1/1/2025 09:50:00" (the specific date and time formatting (12h, 24h, am/pm, etc.) will depend on your system settings). To you and I, we see a date, because that's how our brains work. To Numbers, though, it's just a stream of characters.


Compare that with my version - I used your existing logic to parse the valid DATE() object, to which I added a number of hours and minutes via the DURATION() function. This is still a valid date object., thus solving your problem.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

create a Date & Time value from separate date & time text strings

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.