I have several columns containg dates stored as text so 01/04/1984 actually reads 840401 or 01/04/2001 010401. How do I convert this so I can the use the dates to make calculations?
Please try:
=VALUE(RIGHT(A1,2)&"/"&MID(A1,3,2)&"/"&IF(VALUE(LEFT(A1,2))>50,19,20)&LEFT(A1,2))
which assumes years 31-99 are 20th century and others 21st.
Related
I am working on a SSRS report which compares data of 2 given months. I'm categorising the chart based on Day and time in the following format 1, 6:00 AM. I get this column from the T-SQL itself. But the axis does not come properly. It looks like below now which doesn't make sense. I want it to be in order from 1st to 30th with the time component.
I guess I need some kind of sorting on X-axis with respect to date time. Please help!
After deleting from sorts from chart I'm getting some extra repitive dates after comparing all 30 days of both months. Data from the query looks alright to me!
Thank you!
Ok. Large query
You X-axis are show value in format date,hh mm tt Right ?
Then you want to sort them with day number 1 - 30.
From your query I suggest you add 1 field is like this CAST(SampleCollected AS DATE) [orders] and use this field in Order in Query or Sort on SSRS (not recommend ) and if you use Order in Query must delete sort condition on chart sort.
But if result still not you want try to add MONTH(SampleCollected) As MonthG to order again like this
ORDER BY MONTH(SampleCollected),CAST(SampleCollected AS DATE)
Hope it's Help.
Here trip 1 involves 2 activity_code in a single day and also concludes in a single day and most other activities are just single day but i have one trip that span over more than one day.
What could be the best possible way to store date range for that column that span more than one days.
Splitting the column into multiple begin date and end date just doesn't make sense as there would be many blank columns?
trip_id(pk,fk) Activity_code(pk,fk) date
1 a1 1st October 2015
1 a2 1st October 2015
2 a3 2nd -5th October 2015
Keep in mind that i need to search the activity_code on basis of month. such as list all the activity code that occur in October ?
Is it possible to insert a range of date in a single column or any other design solution ?
Is there any datatype that can represent the date range in single value ?
PS: oracle 11g e
Store the date ranges as FirstDate/LastDate or FirstDate/Duration.
This allows you to store the values in the native format for dates. Storing dates as strings is a bad, bad idea, because strings don't have all the built-in functionality provided for native date types.
Don't worry about the additional storage for a second date or duration. In fact, the two columns together are probably smaller than storing the value as a string.
Splitting the date into start date and end date would be ideal. Storing dates as strings is not recommended. If you store your dates as strings then there is a possibility of malformed data being stored in the column since a VARCHAR2 column will allow any value. You will have to build strong validations in your script while inserting the data which is unnecessary.
Secondly, you will not be able to perform simple operations like calculating the duration/length of the trip easily if both the start_date and end_date are stored in the same column. If they are stored in different columns it would be as simple as
SELECT trip_id, activity_code, end_date - start_date FROM trips;
With SAS SQL (or just SAS) I need to use a variable for a calculation based on the year portion of a different date field. The variable's name contains the year that I'd need to match from the year portion of the other date variable. How can I select the right variable to use for my calculation?
For example, I need to select which one of these to use:
GRADE_2013
GRADE_2014
GRADE_2015
by looking at a date field of the format 15JAN2014 - so from that year of 2014 I want to grab the value from GRADE_2014 to use in another calculation.
You have a few options, one is an array with a year index and another is the VVALUEX function that looks up the value of a variable.
Data One;
set Have;
array grades(2013:2015) grade_2013-grade_2015;
*Array method;
variable_want1 = grades(year(date_field));
*VValueX method;
variable_want2 = vvalues('grades_'||put(year(date_field), 4.));
run;
Generally, this sort of problem becomes much easier if you can transpose your data into a more normalized format.
So instead of having three grade_YYYY variables with year suffixes on each, transpose each record into three records, with variables YEAR and GRADE.
Thanks so much for the great answers...I'm a novice so I'll have to go the non-array approach at least to start.
I have around 20,000 entries in a SQL table for which a date column is of the form
YYYY-MM-DD HH-SS. I would like to convert this format to a YYYY-MM-DD format so I can run a query on all of the entries that will count the number of entries based on
a) the month under which they fall
b) the day
I'm new to SQL and not sure if there is a way to loop through all of the entries and check based on the required criteria; and as such, would greatly appreciate any help.
I unfortunately, cannot send a screenshot of the table since the data is classified.
You don't need to change the data in the table. Most databases have year() and month() functions, so you could do:
select year(datecol), month(datecol), count(*)
from sqltable
group by year(datecol), month(datecol)
order by year(datecol), month(datecol);
If these specific functions are not available, then I'm sure your database supports something similar.
I am trying to mimic the solution in this answer post: Sqlite convert string to date
The problem I am running into though is that my raw text date field contains dates in the following format:
1/5/2014 0:00:00
instead of:
01/05/2014 0:00:00
How can I account for this single digit month/day variability and adapt the code for my purpose? I cannot think of a decent way. I have thought of using excel to create a conversion table that I could join upon. Is there a more elegant approach?
Edit on 10/2/2014:
I would have thought there would be more like 81 possible combinations to identify. Or Maybe there is a simpler way I am not thinking of?
1/1/
1/2/
1/3/
1/4/
1/5/
1/6/
1/7/
1/8/
1/9/
2/1/
2/2/
2/3/
2/4/
2/5/
2/6/
2/7/
2/8/
2/9/
...
There are eight different combinations of one- or two-digit fields; you just have to check for all of them:
SELECT CASE
WHEN Trans_Date LIKE '_/_/____ _:__:__' THEN substr(Trans_Date, 10, 1)
WHEN Trans_Date LIKE '_/_/____ __:__:__' THEN substr(Trans_Date, 10, 2)
...
END AS Hour,
...
FROM LS2014