RedCoupe

Archive for July, 2011

Order by date when stored as a nvarchar

by on Jul.21, 2011, under Web design / development

Just had a MS SQL Server problem where as the title suggests, I wanted to order a query by a date column to show the most recent entry at the top, but it wasn’t working because the date column was stored as a nvarchar instead of a datetime.

I tried various things like CONVERT…. and CAST…AS datetime, but for whatever reason I could not get this to work.

I got round this by doing some string concatenation:

SELECT * FROM tbl_articles
WHERE visible = 1
ORDER BY RIGHT(dateval,4)+SUBSTRING(dateval, 4, 2)+LEFT(dateval,2) ASC

The date was stored in the table as text like 22/10/2011, the above concatenating turns it into 20111022 which can easily be sorted in the proper order.

I know this is more than likely not the best way of doing it and should have persevered with the casts and converts but it works fine for the minimal amount of data I have in that table. No doubt I’ll have to revisit this if the number of records significantly increases.

Leave a Comment : more...

Modified styles in WordPress

by on Jul.14, 2011, under Web design / development

I have another site produced with WordPress and it uses a modified version of the Twenty Eleven theme.

The trouble was that whenever I applied an update to the theme, it obviously overwrote my modified style.css. I suppose if I wasn’t lazy I could have copied the theme to a new folder and simply used the copied theme. Although I do like getting updates including any improvement tweaks etc.

To get round this I found a great plugin called Style Press which was made by grandslambert who has also produced some other handy plugins. So I installed it, added my custom css, reverted the style.css back to the original version, and it worked perfectly. So in future whenever I apply a new update to this theme, unless class or id names change, the site will always look the same because the extra bit of css is always added at the end of all the other style includes in the html.

Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!